Yeah, I just solved the issue, and I hope the details are helpful to others.
In the framework, there is a complicated subclass of NSView
, which contains many controls such as NSSplitView
NSOutlineView
and IKImageBrowserView
, NSPathControl
and etc; the framework contains a H file, a M file and a XIB file; H and M define the MyView
class; in the XIB, there is a View object whose class is MyView
.
On the application side, users need to drag a NSView
item onto the main window of their app, and assign an outlet to the view, let's say mainView
, and in the applicationDidFinishLaunching
function of the "consumer" app, the follow code is necessary
NSBundle *frameworkBundle = [NSBundle bundleForClass:[MyView class]];
NSNib *nibby = [[[NSNib alloc] initWithNibNamed:@"MyView" bundle:frameworkBundle] autorelease];
NSArray *topLevelObjects = nil;
BOOL flag = [nibby instantiateNibWithOwner:nil topLevelObjects:&topLevelObjects];
assert(flag);
for (id topLevelObject in topLevelObjects) {
if ([topLevelObject isKindOfClass:[MyView class]]) {
[mainView addSubview: topLevelObject];
MyView* xView = topLevelObject;
[xView setFrameSize:mainView.frame.size];
break;
}
}
In the code above, the XIB files is loaded, thus the MyView
object is initialized, then we fetch it out of the XIB, resize it and add it to the main view of the window