How do I load resources from NSBundle correctly?
How do I load resources from NSBundle correctly?
- Subject: How do I load resources from NSBundle correctly?
- From: Gore <email@hidden>
- Date: Sat, 24 Nov 2001 16:46:43 +0200
What should I do to load the resources inside a bundle in a correct
way ? here is what I do right now, this code is inside my NSDocument
class, used to load the interface for my plugins, but if I open a new
document and try to load it again, it gives me the "Error in loading
interface." error, hmm...please help, newID is a class instance in my
NSDocument.
- (IBAction)runPluginWithMenu:(id)sender // sender is a NSMenuItem from
the plugin menu
{
NSBundle *thePlugin = [NSBundle bundleWithPath:
[[[NSBundle mainBundle] builtInPlugInsPath]
stringByAppendingFormat: @"/%@.bundle", [sender title]]];
currentPluginName = [sender title]; // save the name for later use
if ( runningPlugin == NO ) // just to be safe...so that you can't
run many plugins at the same time
{
if ( [thePlugin load] )
{
newID = [[[thePlugin principalClass] alloc] init];
[newID setCurrentDocument: self]; // give the plugin
instance the current document to play with
if ( [newID pluginIsGUI] ) // if YES, then load the resources
{
if ( [NSBundle loadNibNamed: @"PluginInterface" owner:
newID] ) // should the owner be a class or instance!?
{
[pluginBox setContentView: [newID pluginView]];
runningPlugin = YES;
[NSApp beginSheet: pluginsPanel modalForWindow:
docWindow
modalDelegate: self didEndSelector: NULL
contextInfo: nil];
}
else
NSRunAlertPanel( [sender title], @"Error in loading
interface.", @"OK", nil, nil );
}
else
{
runningPlugin = YES;
[self runThePlugin: self];
}
}
else
NSRunAlertPanel( [sender title], @"Error in loading
plugin.", @"OK", nil, nil );
}
}