Loading a UINavigationController from another cone automatically using the UITabBarController

I think I found a reason: the "Document Information" window in IB has a warning: "Selected navigation controller (second)" has the nib name property set to "SecondView.nib", but this view controller is not intended to have its own presentation such way. "

Bummer.


I built nib in the Builder interface, which has a UITabBarController at the top level and switches between UINavigationController s.

It works fine when everything is in the same nib file, but I would like to use separate nib files for UINavigationController s.

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

second nib

and all i get is:

 // imgur has lost the image, sorry // 

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

I would like TabBarController handle loading and unloading knives.

+4
source share
5 answers

Just replace the UINavigationController with 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) 

In the inspector, you set the nib of the First View controller to a nib file containing the actual view objects (since you are trying to split them into separate files, which is good).

You have one tab, on this tab there is a navigation controller that loads the First View Controller as its root view.

Done.

+5
source

I have not tried configuring the UINavigationController via IB. I have several screens, each of which is stored in a separate xib, and there is a corresponding class that extends the UIViewController. In applicationDidFinishLaunching, I initialize the UIViewControllers with xib, but then manually create the UINavigationController, add the view of the navigation controller to the window, and click the first view of the navigation controller.

Not sure if this helps.

 - (void)applicationDidFinishLaunching:(UIApplication *)application { navigationController = [[UINavigationController alloc] init]; FirstViewController * viewController = [[FirstViewController alloc] initWithNibName:@"FirstView" bundle:nil]; [navigationController pushViewController:viewController animated:NO]; [viewController release]; [window addSubview:navigationController.view]; [window makeKeyAndVisible]; } 

Above FirstViewController extends the UIViewController, in IB you create your view and then set the file owner class to the class (for example, here FirstViewController) and connect the file owner view to the UIView view.

+5
source

I believe that you are looking for something like this. You would replace "whatever" with the name of the second nib file.

 newNavController = [[UINavigationController alloc] initWithNibName:@"whatever" bundle:[NSBundle mainBundle]]; 
+1
source

First, it looks like you have a UITabBarItem under the navigation controllers, and not directly under the UITabBarController . This may be part of your problem.

Secondly, when you add a UITabBarController to IB and click on its icon in the list of top-level objects (your first screenshot), the attribute inspector allows you to change the type of view controller for each tab. Using this, you can change them all to navigation controllers if you want. In addition, since you want to load custom views and view controllers from other pens, if you look at the View Controller section at the bottom of the attribute inspector, you can select a thread from your project to load the view. Assuming the nib "File Owner" is set to your UINavigationController subclass, everything should work fine.

All this without a lot of coding work. Let me know if you want screenshots, what I'm talking about if you cannot find these panels.

+1
source

I found the same warning. I have saved all view controllers in separate xib files. I got rid of it by deleting the name .nib and leaving it empty.

0
source

All Articles