We have some generic window loading code that must instantiate the window
controller first, then calls initWithWindowNibName: on that. This made it
impossible to provide a subclass of our generic window controller subclass in
the xib, but now we need to do this. Since NSNib doesn't have a method or
property for the file's owner, the best way I know of to get this is to look
for the window in the nib (see function below), gets its controller, get the
controller's class, then release the window so we can create things in our
"normal" way.
If there some better way to get the file's owner class?
id LoadObjectFromNibNamed(NSString* const nibName, const Class ofClass)
{
NSNib* nib = [[[NSNib alloc] initWithNibNamed:nibName
bundle:nil] autorelease];
NSArray* topLevelObjects = nil;
id result = nil;
if([nib instantiateNibWithOwner:nil topLevelObjects:&topLevelObjects]) {
for(id topLevelObject in topLevelObjects) {
if([topLevelObject isKindOfClass:ofClass]) {
result = topLevelObject;
break;
}
}
for(id obj in topLevelObjects) {
if(obj != result)
[obj release];
}
}
return result; // Caller will own this.
}
--
Steve Mills
office: 952-818-3871
home: 952-401-6255
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]