开发者

Load Xib Files with NSView

I've a Custom View in MainMenu.xib which will contains 2 subviews. These subviews should be loaded from some xib files which have a single NSView. How can i do this? The Classes that contains IBOutlet and IBActions for each xib from which class should inherit? And for each xib i must set the file owner to the Class that contains开发者_如何转开发 outlet/actions?


You can use:

- (BOOL)loadNibNamed:(NSString *)nibName
               owner:(id)owner
     topLevelObjects:(NSArray * _Nonnull *)topLevelObjects

to load your xib file, the topLevelObjects parameter is an Array passed by reference, after calling the function it will contain the array of objects from your xib, what you are interested in here is an object of type NSView, you can add the view to wherever you want


Your custom view or main menu's header file should #include the 2 subviews that you mention, and you should list them as IBOutlet members and IBOutlet properties. (don't forget to synthesize!)

In your xib file, you should be able to drag in 2 NSView's and then set their class to your 2 subclasses, and then link them by dragging from 'file's owner' to the object in the 'objects' list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜