views:

170

answers:

2

If I am loading a view from another NIB, how do I set the File's Owner view property? IB is not letting me hook it up to my View Controller which is loading the external NIB.

My NIB looks like this:

File's Owner - Identity is set to LBRootViewController

First Responder

LBTableViewController - Identity is set to LBTableViewController, NIB Name is LBTableViewController
+1  A: 

Select the File's Owner proxy (in the NIB window) and switch to the identity tab in the inspector palette (the far-right tab with the circle-i icon). Set the Class field to NSViewController (or whatever your view controller subclass is, if any). You should now be able to drag your outlet!

Wevah
I tried setting File's Owner to LBTableViewController but I am still not able to drag my outlet. Do I need to write any code in my H file?
Sheehan Alam
Does `LBTableViewController` inheriting from `NSViewController`? Make sure the `@interface` line looks something like `@interface LBTableViewController : NSViewController`. Or, if you don't want it to inherit from `NSViewController`, make sure you have your `view` instance variable declared as an `IBOutlet`: `IBOutlet NSView *view;`.
Wevah
it is inheriting from UIViewController, thoughts?
Sheehan Alam
Oh, I missed the `iphone` tag. `UIViewController` is set up pretty much the same way WRT the `view` outlet, though, IIRC…
Wevah
The only other thing I can think of right now is, "Is your xib saved to the project directory and added to the project?"
Wevah
yes it is. i tried this approach on a clean, new project same results.
Sheehan Alam
+2  A: 

You can't set the File Owner to a view controller defined in another nib because you can't set outlets across nibs. Each view controller has to be the File Owner of its own nib.

No nib should have two controllers that are active at one time. The setup where you have a root controller in a nav does not actually have two controllers but instead causes the root controller to load the second controller nib at runtime.

It looks like you should have two nibs here: LBRootViewController.xib and LBTableViewController.xib. The File Owner of each nib is an instance of the classes the nibs are named for. You can create an outlet in the LBRootViewController class that points to an instance of LBTableViewController. When LBRootViewController.xib loads it does not trigger the loading of LBTableViewController.xib until the attribute serving as the outlet is accessed.

TechZen