How to load a nib from a path
How to load a nib from a path
- Subject: How to load a nib from a path
- From: Bill Houston <email@hidden>
- Date: Fri, 20 Feb 2004 07:46:34 -0800
I am writing a framework that can be included in the framework folder of an
application bundle, or dynamically loaded by the application at run time.
This framework includes a localized nib file in it's resource folder. The
nib file can be loaded normally when the framework is in the applications
bundle, but when the framework is loaded dynamically I am passed a path to
the framework by the application that loaded it. I need to load the nib
using the path, but I have not found a straight forward way to do it. I
have included the code for my best attempt below:
- (id)init:(const char*)frameworksPath {
self = [super init];
// init the application
NSApplicationLoad();
// check to see if we got a path from our host application
if(frameworksPath == NULL) {
if (![NSBundle loadNibNamed:@"MY_UI" owner:self]) {
NSLog(@"failed to load MY_UI nib");
}
} else {
// try to use the path we were given
NSString *pathString = [NSString stringWithCString: frameworksPath
];
NSBundle *frameworksBundle = [NSBundle bundleWithPath: pathString ];
if(![frameworksBundle load]) {
NSLog(@"failed to load Nib from specified location");
if (![NSBundle loadNibNamed:@"MY_UI" owner:self]) {
NSLog(@"failed to load MY_UI nib from main bundle");
}
}
}
noPath:
noBundle:
return self;
}
This code works when frameworksPath is NULL, but does not when
frameworksPath has a path to the frameworks bundle.
It seems that "[frameworksBundle load]" will not load a nib, only the code
resources, and "loadNibNamed" does not work with a bundle.
I have searched and searched for a way to load a nib from a specific bundle,
but cannot find one. Can anyone point me in the right direction?
Thanks,
Bill
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.