Is it correct that a NIB can't be used by many different classes?
Example: Can I make a NIB which represents an view hierarc开发者_Go百科hy, 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?
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.
there is a loadNibFileNamed:withOwner method. The owner objects do need to have the right outlets, of course...
精彩评论