views:

31

answers:

2

Example: Can I make a NIB which represents an view hierarchy, and use this NIB with multiple different UIViewController subclasses?

Because: The File's Owner seems to be set hard to a specific class. What's the point of that? Is the Nib Loading System looking through all xib files and figuring out from them which Class wants which xib? For me, it would be a lot more logical if the classes told the Nib Loading System that they want to have xib xyz loaded. Actually this whole nib stuff is just an archive for objects, pretty much the same thing like if I would create those programmatically and connect them with eachother. Or not?

A: 

there is a loadNibFileNamed:withOwner method. The owner objects do need to have the right outlets, of course...

Mark Bessey
Which class does define this method? The docs show no matches for this.
dontWatchMyProfile
It's defined in NSBundle
dontWatchMyProfile
Docs link here:http://developer.apple.com/mac/library/documentation/cocoa/reference/ApplicationKit/Classes/NSBundle_AppKitAdditions/Reference/Reference.html#//apple_ref/occ/clm/NSBundle/loadNibNamed:owner:
Mark Bessey
+1  A: 

Call

[[NSBundle mainBundle] loadNibNamed:@"MyNIBFile" owner:myViewController options:nil];

As Mark said, the owner object must have the right outlets.

If you want to use -initWithNibName:bundle:, the cleanest way IMO would be to have all view controller inherit from a common subclass where you define the outlets they have in common. Then you can use this class as the File's Owner's class in IB.

Ole Begemann