If this helped you, please consider downloading my FREE iPhone app "Hydrate Yourself"and leaving a review.
There are a whole bunch of tutorials to create a Navigation Controller inside a TabBarController with XCode3. But there are a number of small changes in XCode4 which can trip up someone not familiar with them. So this guide is essentially an updated version of those other guides, designed to create the same simple demo using the new tool.
1. Create a new Project
We are going to start with a Tab Bar Application, so go ahead and create a new project as usual. I'm calling mine Navigation Tab Bar.
2. Select the Tab Bar
Click MainWindow.xib and you should see the integrated Interface Builder. On the left is a section called Objects, select the Tab Bar Controller.
3. Add the Navigation Controller
On the right side of your screen click the Utilities box. This is new in XCode4 and should look familiar if you've been using XCode3. At the bottom find the Navigation Controller and drag it into the Tab Bar in the middle of your screen.
4. Configure new tab
Back in the Objects section you can now expand the Navigation Controller and select the View Controller object. Now on the right side you can select the Identity Inspector at the top and put in your UIViewController's class name. For the purpose of this demo I am calling it "YourNewViewController" which we will make at the end.
Once that is done switch to the Attribute Inspector and put in the name of your XIB file in the NIB Name section. Note: do not add the .xib extension, this will cause a runtime crash.
5. Create the new UI View Controller
This is probably familiar to you already, create file from the File menu and select a UIViewController subclass.
Be sure to select With XIB for user interface |
Use the same file name as you used before. |
6. Add an IBAction
We will be adding a button to push a view onto the navigation controller. Open up the header file and add an action.
Switch to the implementation file and add another few lines for a simple call to pushViewController.
This is the simplest pushViewController line I could come up with |
7. Add a button
Select YourNewViewController.xib in the file menu. Adding a button is a simple matter of dragging/dropping from the bottom right Objects section.
Next you link the button to the new IBAction by right clicking the button and dragging the arrow to File's Owner, in the Placeholders section. Select buttonPushView.
Next you link the button to the new IBAction by right clicking the button and dragging the arrow to File's Owner, in the Placeholders section. Select buttonPushView.
8. You're done!
All thats left now is the build and run (Command-R). Select the second tab to see your new Navigation Controller and click the button to see it in action.