Load NIB in dynamically loaded bundle.
Load NIB in dynamically loaded bundle.
- Subject: Load NIB in dynamically loaded bundle.
- From: Erwin Veugelers <email@hidden>
- Date: Mon, 19 Nov 2001 13:56:50 -0700
Hi y'awll,
I've seen a few mentions about this in the archives, but no clear
answers to what I'm running into.
I'm writing a simple application that parses files from one format and
writes them out in another. I'd like the application to be extensible
with additional formats later on, so I'm playing with dynamically loaded
bundles containing the importer and exporter objects. I would like each
plug-in object to provide the main application with a customized NSView
instance to act as a plug-in specific options panel.
Currently, the code for my "SimpleParser" class looks something like
this:
@interface SimpleParser : NSObject
{
IBOutlet NSView* optionsView;
}
- (BOOL)loadOptionsView;
- (NSString*)getName;
- (BOOL)hasOptions;
- (NSView*) getOptionsView;
@end
@implementation SimpleParser
- (BOOL)loadOptionsView
{
return [NSBundle loadNibNamed:@"SimpleParser.nib" owner:self];
}
- (NSString*)getName
{
return @"Simple Parser";
}
- (BOOL)hasOptions
{
return YES;
}
- (NSView*) getOptionsView
{
return optionsView;
}
@end
"optionsView" is the name of the IBOutlet that is connected to a custom
NSView instance in the bundle's NIB file, "SimpleParser.nib", connected
to the "File's Owner" instance, which is set to be of the "SimpleParser"
class. By the way, the "loadNibNamed" call returns YES.
In the main application's "PluginManager" class, the "loadParsers"
method contains:
- (void)loadParsers
{
id p;
NSString* path;
path = [[[NSBundle mainBundle] builtInPlugInsPath]
stringByAppendingString:@"/Plugins.bundle"];
bundle = [NSBundle bundleWithPath:path];
p = [[[bundle principalClass] alloc] init];
[p loadOptionsView];
(... p is now stored in an NSArray for later reference ...)
}
"Plugins.bundle" is the bundle containing the SimpleParser class, with
SimpleParser set as the bundle's principal class. The bundle has been
copied into the Contents/Plug-ins directory in the main application's
bundle.
When the parser is later extracted from the storing array and addressed
with [parser getOptionsView], the method returns nil. If I replace the
line "return optionsView" in SimpleParser with "return [[NSView alloc]
init];", I get a nice (albeit empty) NSView object, but returning the
optionsView IBOutlet connection returns nil.
This exact same setup, but with all sources and the additional NIB file
stored in the application bundle (and without the two lines loading the
bundle), works just fine, but as soon as I move the SimpleParser code
and NIB to a separate bundle (in a separate PB project file), the nil
thing happens. The bundle loads fine, because "getName" and "hasOptions"
in "SimpleParser" perform as expected.
Any ideas, anyone?
Erwin Veugelers
-----------------------------------------------------------------------
Erwin Veugelers
Instructional Designer - Computer Based Instruction
Instructional Media & Design
Grant MacEwan College
Edmonton, Alberta, Canada
email@hidden
-----------------------------------------------------------------------