Re: How to load a nib from a path
Re: How to load a nib from a path
- Subject: Re: How to load a nib from a path
- From: Steve Stockman <email@hidden>
- Date: Sun, 7 Mar 2004 09:53:37 -0600
On Feb 20, 2004, at 9:46 AM, Bill Houston wrote:
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.
Did you ever resolve this problem? I ask because I have a similar one.
I had some code and an accompanying nib inside an application, and it
worked fine. But when I split it out into a framework, the nib no
longer loads, whether the framework is linked into the app or is loaded
dynamically.
I began with the following in the framework's principal class:
- (id) init
{
if ((self = [super init]) != NULL)
{
if ([NSBundle loadNibNamed:@"MyNib" owner:self])
{
// (other initializations)
}
else
NSLog (@"Nib load failed!\n");
}
return self;
}
I was able to instantiate the principal class, but got the "Nib load
failed!" error. So to make sure it was looking in the right place, I
replaced the "loadNibNamed:" line with the following:
NSDictionary* info = [NSDictionary dictionaryWithObject:self
forKey:@"NSOwner"];
NSBundle bundle = [NSBundle bundleForClass:[self class]];
if ([bundle loadNibFile:@"MyNib" externalNameTable:info
withZone:[self zone]])
Stepping through in the debugger showed "bundle" to properly indicate
the framework, but the nib still wouldn't load. So I replaced the
"loadNibFile:" line with:
NSString nibPath = [bundle pathForResource:@"MyNib" ofType:@"nib"];
if ([NSBundle loadNibFile: nibPath externalNameTable:info
withZone:[self zone]])
Stepping through again shows "nibPath" to be the correct path to my
nib, but it still will not load.
Again I note that the very same nib will load when the same principal
class is compiled directly into my application.
Does anyone know of a way to determine why NSBundle is unable to load a
nib?
--
Steve Stockman
Architect, Norton Utilities for Macintosh
Symantec Corporation
_______________________________________________
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.