Saturday, September 10, 2011

How to load a custom RootViewController in a NavigationController via XIB

This is basically an addendum to my previous post Add a UINavigatorController UI and load from XIB in an empty (single window) iOS App;

Once you have a base or customized UINavigationController loaded via XIB, you might want to load a custom UIViewController into that Navigation Controller. This is actually very simple.

First write a custom UIViewController via the normal Objective-C derivation process. I am not going into that detail. Let's say, you call it, RootViewController

Now, you just need to select the View Controller object in the tree under Navigation Controller. See below:

Now, in the Identity inspector, set the class to RootViewController. See below.
That's it. Now if you build and run, iOS automatically creates an instance of your customized RootViewController class and load it up in the Navigation Controller.

It's that simple.

No comments: