Loading .nib files from plugins (NSBundle)
Loading .nib files from plugins (NSBundle)
- Subject: Loading .nib files from plugins (NSBundle)
- From: Ivan Ramirez <email@hidden>
- Date: Thu, 22 Feb 2007 20:48:53 -0700
Hello there
I am currently trying to understand how to load separate NSViews from
external plugins into a preferences pane I developed.
on the plugin side i created a NSView that has 2 outlets and 1 action
these two actions are connected to a controller class that inherits
from nsobject.
on the main plugin interfacing code i have this function
- (id) prefPaneInterface
{
if (m_pluginView==nil)
m_pluginView = [[PluginView alloc] init];
return m_pluginView;
}
on the prefpane side I have this test loading code (in a separate
class from the main delegate class):
- (void)loadModule:(NSString *)plugInPath
{
NSBundle * plugIn = nil;
Class plugInClass = nil;
plugIn = [NSBundle bundleWithPath:plugInPath];
plugInClass = [plugIn principalClass];
// If the principal class is valid
if (plugInClass)
{
m_tempBundle = [plugIn retain];
m_tempCalled = [module prefPaneInterface];
// This was based on apple code related to loading nib files
// http://developer.apple.com/documentation/Cocoa/Conceptual/
LoadingResources/CocoaNibs/chapter_3_section_6.html
NSMutableArray* topLevelObjs = [NSMutableArray array];
m_nameTable = [NSDictionary dictionaryWithObjectsAndKeys:tempCalled,
NSNibOwner,topLevelObjs, NSNibTopLevelObjects, nil];
// Window pref is the name of the plugin nib file
if (![plugIn loadNibFile:@"WindowPref" externalNameTable:nameTable
withZone:nil])
{
NSLog(@"Warning! Could not load myNib file.\n");
}
else
{
// actions/outlets work properly here
// setButtonText is the only action on the plugin
[[[m_nameTable objectForKey:NSNibTopLevelObjects] objectAtIndex:1]
setButtonText:@"Testing" ];
// NSView object also works
// Acquire the NSView from the nib file (for currentview)
m_view = [[nameTable objectForKey:NSNibTopLevelObjects]
objectAtIndex:0];
}
}
on the prefpane controller i basically call an accesor that returns
the loaded view from plugin and add it to a custom view that i have
on the main window such as:
[m_customView addSubview:[pluginloader currentview]];
Everything loads fine so far; but the view cannot be modified, the
outlets of the plugin view do not respond. I have only 2 outlets, a
button and a textfield. The button does have any visual feedback at
all...
Can someone give me any help (via code) that would help fix that
problem? I have been looking at forums and sample code but i havent
been able to figure it out.
Thanks in Advance
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden