Does the UINavigationController NIB require the file owner to have a view?

I am having trouble installing View Viewer View Controller nib by default in Interface Builder. Here is my setup:

I have a TabBar based application where I load a navigation controller as a modal view ...

MyNavCtrlrSubClass *menu = [[MyNavCtrlrSubClass alloc]initWithNibName:@"MenuController" bundle:nil]; [tabBarController presentModalViewController:menu animated:anim]; 

The MenuController itself is structured as follows:

  MenuController.xib
   File Owner (MyNavCtrlrSubClass: UIViewController)
   Navigation Controller (UINavigationController)
     Navigation Bar (UINavigationBar)
     Root View Controller (Nib Name is set to load AnotherViewController.nib)
       Navigation Item -> (UINavigationItem)

All this works fine, except when loading MyNavCtrlrSubClass I get the following error:

Loaded the "MenuController" nib but the view outlet was not set

It is clear why this is happening. The file owner does not have an output connection to view it. The question is, what should I set as my presentation, and should I install something first? The navigation bar is the only candidate for MenuController.xib, but it will simply be the size of the UINavigationBar so to speak, in full screen mode.

I obviously missed something at IB, but what? MyNavCtrlrSubClass.m does not have the code itself, except for IBOutlet for UINavigationController. Am I mistaken when trying to install this completely in IB? The idea is to save the modal Navigation Controller in one tip, and all the views that it loads in separate tips, but since the MenuController is just a navigation container and doesn't contain any views, I'm obviously designing it wrong. :)

If you are wondering why I am not designing it in any other way, this is because I am trying to obey my (possibly erroneous) perception of how IB asks you to build an ideal hierarchy.

Any help would be greatly appreciated.

+6
iphone uiviewcontroller interface-builder uiview uinavigationcontroller
source share
3 answers

I think you may not understand how the file owner should be used in the NIB file. I wrote an answer describing the file owner under another question .

When calling this line:

 [[MyNavCtrlrSubClass alloc] initWithNibName:@"MenuController" bundle:nil] 

Create an instance of MyNavCtrlrSubClass and tell it to download @ "MenuController". Then in the MenuController.xib file there is a second unrelated UINavigationController with things inside it. When MenuController.nib is loaded at runtime, this second navigation controller will be created.

The second problem is that telling the UINavigationController to load the NIB file is not very smart, because navigation controllers create and manage their own views. Are you sure you want to create a root view controller and tell the view manager to load the NIB file.

Try the following:

 MyRootViewController *rootController = [[[MyRootViewController alloc] initWithNibName:@"AnotherViewController" bundle:nil] autorelease]; MyNavCtrlrSubClass *menu = [[MyNavCtrlrSubClass alloc] initWithRootViewController:rootController]; 

Where your XIB file is as follows:

  • File owner (the class is set to MyRootViewController, the output for viewing is connected to the next UIView)
  • Uiview
    • Subview a
    • Subview b

After you have handled how this all works, you might also consider creating an instance of the navigation controller and the root view controller in a single XIB file, as if you started to do it in the code you published.

+5
source share

The essence of this question was pointed out by Travis himself: "How would you load the nib navigation controller by constructing it as much as possible in Interface Builder?" And also from the example, it looks like this means UINavigationController and its associated UIViewControllers.

With this interpretation, the answer is that you cannot fully configure the UINavigationController and UIViewControllers in the same XIB. Yes, intuitively I want to do this so that you are not crazy.

When I say that you cannot do this, I mean that the most commonly used infrastructure methods have no way of dealing with this. No [UINavigationController alloc] initWithMegaNibName . Yes, you can use almost everything in one XIB and write code to hydrate objects in special ways, but I don’t think what you are looking for.

You can use two or more XIBs, as John suggested, but then everything is less self-sufficient, and so you have many people who find it easier to make part or all of the controllers in the code.

Unfortunately, there is no 1: 1 correspondence between the features of Interface Builder and the code, as on other dev platforms. I generally prefer to allow designers to participate as much as possible in creating assets, but most of them that I know do not code objective-c.

+1
source share

In IB, in the MenuController element, add a UIView and set this view as an output. You will need to set this view for the UIViewController. Here is a quick link to an Apple page showing the basic setup. Not sure if this will help you at your current stage.

0
source share

All Articles