I have a MyCustomView subclassed from NSView designed in a .xib.
I would like to insert this view into some of my other xib\'s round my application. How should
I'd advise just doing it programmatically:
xib/storyboard and set the custom class to your custom view's classIBOutlets, etc. as neededNSView of the xibinitFromFrame in your custom view's class roughly as follows:
@interface CustomView ()
{
__strong NSView *nibView;
}
@end
@implementation CustomView
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSArray *nibObjects;
[[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self topLevelObjects:&nibObjects];
nibView = nibObjects[1];
[self addSubview:nibView];
}
return self;
}
The IBOutlet are connected up immediately after the loadNibNamed call, so you can do further initialization from there.
Another option is to do things purely programmatically:
1. In your custom xib, set the root View's class to your custom class
2. Implement awakeFromNib in your custom class to perform initialization
3. Call loadNibNamed: on your custom xib and programmatically add it to the user interface without interface builder.