Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading UINavigationController from another nib automatically by UITabBarController

I think I've found the cause: Document Info window in IB has a warning: "'Selected Navigation Controller (Second)' has nib name property set to 'SecondView.nib', but this view controller is not intended to have its view set in this manner."

Bummer.


I've built nib in Interface Builder that has UITabBarController at top level and switches between UINavigationControllers.

It works fine when everything is in a single nib file, but I'd like to use separate nib files for UINavigationControllers.

Starting with Apple's TabBar template, if I just change class of SecondView to UINavigationController, it all breaks:

second nib

and all I get is this:

// imgur has lost the image, sorry //

Is it possible to have separate file for UINavigationController without programmatically setting everything?

I would like TabBarController to handle loading and unloading of nibs.

like image 595
Kornel Avatar asked Dec 17 '22 07:12

Kornel


1 Answers

Simply swap the UINavigationController with the FirstViewController.

So the hierarchy should be like this:

Tab bar controller
-----Tab bar
-----Navigation Controller
----------First View Controller
---------------Navigation Item
----------Tab bar item (First)
-----Navigation Controller
----------Second View Controller
---------------Navigation Item
----------Tab bar item (Second)

You set the nib of First View Controller in the inspector to the nib file containing the actual view objects (Since you are trying to split them into separate files, which is a good thing).

You have one tab, that tab has a navigation controller which loads First View Controller as its root view.

Done.

like image 178
Corey Floyd Avatar answered Jan 21 '23 13:01

Corey Floyd