How to load a xib file from a storyboard? - iphone

I am new to iOS programming and I am working on a project which will use both XIB files and storyboard.
I have two modules in it basically. First module is made from XIB files which also runs independently. I have made another module using storyboard and I had to integrate these two independently running modules. The screen of my first module which I want to connect to my storyboard is a subclass of UIViewController and I was able to do that with the help of stackoverflow (How to load a storyboard from a XIB file?) by creating an object of UIStoryBoard. Now my application is able to go to the storyboard but I can't come back to my first module which is made up of XIB files.
Please let me know how can I connect to the same instance of the last screen of the first module through which storyboard is called so that I can move back and forth through these views easily. Connecting to the same instance of the XIB file is important because it is a chat screen and when I come back to this screen, I would like to get back to the chat where I had left it and also when I come back to the storyboard (by clicking a button on the chat screen) I have a slider on the screen which should display the value which the user must have chosen when they were on this screen last time. I guess creating a new object should give me a new screen which won't work in this situation. This kind of mechanism works well within storyboard with the use of segue where we can define both source and destination view controller.
Please help me achieve the same in my situation.
Please also check the screen shots of the XIB file and the storyboard which I want connected.
Thanks.

Convert the nib files into storyboard, it will help you easier to manage your application.

Well in your case, what i see is from nibs is that there is a navigation controller in storyboard and also there will be a root view controller navigation controller from xib files.
Well the navigation controller stack has all VCs you pushed into and you can get back it in different ways.

Related

iPhone App Development - Few beginner questions

I've been tasked with creating an app, but I have zero experience with iOS development. I have general programming knowledge, particularly with Java, JavaScript and PHP (I'm more a web developer than a programmer). I have dabbled with C, Xcode and various other languages and IDEs in the past, but I remember very little.
I've been following Apple's Developer Library tutorials, and I'm at around the Language stage, where I'm come to a grinding halt. While I slowly progress through learning the basics of Objective-C, there are a few things I'm very confused about regarding development in Xcode that various tutorials seem to completely skip over or just imply that you know what to do, or some just stop right before the part I'm having trouble with.
1) Storyboard - yes or no?
Is it better to start with an empty application and work with the
files or create a template (in my case a tabbed application) and work
with the storyboard?
2) If using a storyboard, do I still need to have a .xib?
Are the User Interfaces more like global templates that the view controllers implement?
If I wanted a different layout for each tab of my app, would I create a .xib for each tab, or just edit the controllers in the storyboard? Am I correct in understanding that the storyboard can have multiple instances/relationships of the same controller, in which case having .xib's would make more sense?
3) If using storyboard, where do the implementation and source files come from?
This is probably a stupid question. I know you can just add them via File -> New, but I don't know how to associate those files with a view controller. Is there a way to have the files created automatically when adding a controller into the storyboard?
Since you're just starting, you should use Storyboards because it lets you link different view controllers(pages on your app, essentially) visually and outside of code. For example, you can link your UITabbedViewController (the part that manages the content of the other tabs) to the pages that represent the content of the different tabs. Basically, your storyboard would have the tabbed view controller in a parent-child relationship with the sub-controllers. You would have one instance of each -- the tabbed view controller, managing an instance of each of the tabs' content and controller. This is the same regardless of Storyboard or xib, but you can connect this more easily in the storyboard.
You can still use a .xib(nib) file for stuff like Custom Table cells or in cases where you want to separate a view element or controller from a storyboard where there are other constraints.
In the storyboard, you subclass the controller class on the sidebar in the visual editor by entering your subclass of say UITabbedViewController in 'Custom Class'. In your file associated with 'MyTabbedController', you implement your stuff.
Great book:
http://www.barnesandnoble.com/w/beginning-ios-6-development-david-mark/1113216077?ean=9781430245124
Good luck!
Storyboards can be appropriate for small applications, where you have ten or twenty screens. When your app contains more than that, you will just get lost in storyboard schema, where all your view controllers will visually look the same.
I prefer not to use storyboard, just separate xib files for each controller.
If you use storyboard, you can create xib files for other parts of application that is not related to SB, and view controllers that is involved in SB has their interface stored in SB, meaning you will have to design them in there, in this one huge storyboard file. I find this very uncomfortable.
As you are new to IB, I would like recommend you to take a look at Auto layout. There is no magic anymore :)
To answer on a point-by-point basis:
I typically use the "Single View" template. It provides everything you need for your first view and can take it from there. It's a clean slate but it already has that first view which will be exactly the same code in 99% of the applications you make.
No, the storyboard file is your xib. You used to have to make a new xib for each new layout, but then Apple introduced storyboards. A storyboard is basically all of your xib's in one file. Rather than make a new xib, drag a new ViewController object onto the document. You typically only have 1 storyboard file or 2 if you want to support both iPhone and iPad layouts.
I don't think you can have it create your source files automatically, but its fairly easy to connect them manually.
Select the ViewController that you want to connect to your source files by clicking on that black bar beneath it. Then go to the bar on the side and go to this panel:
There you enter the name of your custom ViewController subclass where I have put "MyViewController". Hope that helps!

Switching between views not working for iPhone 5.1 (XCode 4.3.2)

I'm trying to develop an iPhone app that uses 4 views(View-based app), and I want to navigate from one view to the other. It would be ideal if for example the Submit ID button automatically sent a message to UIViewController to switch to View 2, and selecting a cell in View 2 would load View 3.
See a screenshot of the Storyboard here.
I'm not sure how to do that, so I've tried using a separate button to switch between views, but that isn't working either and I can't figure out why.
You can have a look at the source code which I've uploaded to Dropbox.
First, I would suggest posting your code in your question. As appreciative as I'm sure other people are that you provided a dropbox link to the code, most people presumably have little interest in downloading the file to their computer, unzipping, and launching the project (me being one of them).
That being said, let's make sure you're clear on Storyboards and the general view controller hierarchy principles. You have, in your storyboard, four UIViewControllers dragged out into your workspace. So, you're not switching the views of a single UIViewController, telling it to switch from View1 to View2 to View3 and so on. You need to be telling the view controller hierarchy (which, in your case, probably needs to be managed by a UINavigationController), to push and/or pop view controller on and off its stack. It appears that you have some segues set up between your view controllers. Are you calling performSegueWithIdentifier:sender: in your code? Alternatively, you could hook up the Submit ID button to perform a push segue to View Controller 2 in much the same manner.
Once you have that working, you can override prepareForSegue:sender: to send information from ViewController1 to ViewController2 and so on.

XCode 4.1 - Multiple view within a XIB

I have created an application successfully and given it a TabBar view controller that is working as i had hoped, but have run into a glitch.
On each xib i load from the tabBar I need to create sub-views that will perform tasks as this interacts with a database (or .. will). I have created my first page and the buttons that will navigate to the views within the XIB, but do not yet nkow how to navigate between views within the XIB itself.
would it be better to have seperate XIB's that load when the buttons are hit?
OR
should i create views within the XIB's for each category and switch between them?
I am still learning and have had some confusion regarding navigation as I already have the TabBar controlling the root of the application. I have been looking for tutorials, but they all seem to start at either navigation controller as the root, TabBar as the root, and nothing like I need for option 1 above.
I can add details of the app if needed, but am looking for guidance for now.
Thank you,
Silver Tiger
To navigate between views the best way is to use a navigation controller pushing/popping separate view controllers, loaded from separate nibs. UINavigationController is a subclass of UIViewController, so you can perfectly put a navigation controller for each tab. You can also use story-boarding in the new xcode 4.2, but I recommend getting comfortable with this before doing so.

iPhone Dev: Tab View controller. Buttons on first view don't show actions in File's Owner

Hey all, I'm really new to iphone development and am getting really frustrated. I know ASP and Javascript and i'm trying to do this objective-c. I took a course on lynda and now i'm trying to hook up a tab view.
I placed buttons on the first view of the tab view controller. I then went into the header file and created the - (IBAction) for the 4 buttons on there and added the function in the implementation file. The problem is when i go back to Interface builder and try to connect the actions to the buttons, they don't show up. I have no actions listed in the File's owner so i can't do anything. Can anyone out there please help! thanks.
damien
You're doing it backwards (IMHO). create the Actions and Outlets (don't forget to save the source), then create the items in IB (note that you have to refresh IB so that it can re-read the source.
In tab view controller app make sure that class of view is your ViewController class and also in MainWindow.xib make sure all tabs are referencing respective ViewController

Moving a 'UITabBarController with UINavigationController' iPhone app to 'UITabBarController with UISplitView' on iPad

I have an app where the appDelegate has a UITabBarController. Each of the tabs has a navigation controller which I currently use to push a single detail view onto the stack in each tab. I am hoping to replace my navigation controller on each of the tabs with a splitViewController. I use the Interface builder to provide the UINavigationController for each tab. I am having trouble loading a nib for each tab that has a UISplitViewController in it. I am getting an instance of the UITableViewController class displaying on the screen, but I am not getting the UISplitviewController or the Popover or the detail view etc. These classes are all working in a standalone app, but I am not able to get them into each of the tabs in one app. Although I am currently using the Interface Builder I am open to doing this programmatically. If someone has suggestions, or an example small project of a Tab based app with individual split views in the tabs I would appreciate it very much. (As this is my first question I am not sure how much code or other pictures from IB would be helpful for me to post. If you need further detail please let me know and I would gladly amend this post.)
Apple documentation
"The split view controller’s view should always be installed as the root view of your application window. You should never present a split view inside of a navigation or tab bar interface."
Moving on...
Not only shouldn't you -- if you do so, an error is thrown when you run. It's impossible.