Having only used storyords to subclass a navigation controller before I cant find any tutorial on how to do this for xibs.
How do I add a naviagtion controller to a certain xib so I can subclass it? Then I can override the rotation for my view. The part im stuck on is how does the view controller know about the navigation controller? In storyboards I would manually hook it up to my view controller. I just cant work it out with xibs?
Ive added a navigation controller next to my views xib…now I need some advice from here.
Also I’ve created iPad views from my original iPhone xibs. When I drag the nav controller from IB its still in the iPhone screen size?
You don’t need to set a
UINavigationControllerin a xib file the same way you would with storyboards, as a xib only represents one screen. The normal thing to would be alloc/init aUINavigationController, and aUIViewController, and set the view controller as the root of the navigation controller before you display it. This can be done in the App Delegate if you want you whole app wrapped in a navigation controller form the start.In the app delegate in a non-storyboard app you would want something like this
Where
self.navigationis aUINavigationControllerproperty or iVar belonging to the App Delegate. If you want to set up the view controller properly in the xib, select the root view in the xib and open the attributes inspector (RHS, the one that looks like a small shield) and choose ‘Navigation Bar’ in the ‘Top Bar’ drop down menu. This will display a navigation controller top bar in xib so you can position the other views accordingly.EDIT
That’s not entirely correct, you can create the navigation controller in a xib file, but I’ve always considered it more hassle than it worth, as there is very few visual elements to it, and they can be set in code very easily.
More info in this tutorial here
http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/