Re: Load NIB in dynamically loaded bundle.
Re: Load NIB in dynamically loaded bundle.
- Subject: Re: Load NIB in dynamically loaded bundle.
- From: Raphael Sebbe <email@hidden>
- Date: Tue, 20 Nov 2001 11:21:44 +0100
This seems just fine to me. Your problem is either that the NIB did not
load (try implementing -(void)awakeFromNib in the owner to see if it
gets called) or the outlet is not connected (double check).
BTW, I wouldn't load all the NIBs at the same time I load the bundles.
This is exactly their purpose : load them individually (lazily) when
needed (faster launch time, less memory used...).
Raphael
On Monday, November 19, 2001, at 09:56 PM, Erwin Veugelers wrote:
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
-----------------------------------------------------------------------
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev