Subject: NSPopUpButton not accepting setMenu: from WindowController code

[myPUBtn setMenu:menu] accepted in MyAppDelegate but does not accept
setMenu:menu when relocated to an NSWindowController. I'm thinking there is
something I have missed about the loading sequence.

When all the code resided in MyAppDelegate I could load a list of plugins,
build a menu item for each, and call setMenu:menu on the instance of
NSPopUpButton connected in IB to a reference in the delegate. The appDelegate
was getting messy so I refactored this window out to a NSWindowController, call
-[controller initWithWindowNibName:owner:]
and remade all the connections. Several times to be sure.

The passage of code which builds out the menu items successfully executes.
NSLog(@"%@",menu) shows the content expected.
NSLog(@"%@",[myPUBtn menu]) logs (null).

When the popup menu was being successfully populated from the AppDelegate I was
running the code which does this work from -(void)
applicationWillFinishLaunching; Now that it resides in the WC I have tried
variously: -windowDidLoad, -windowWillLoad, -awakeFromNib (not invoked), and
even tacking it directly onto the end of initWithWindowNibName:owner: The
results are the same: the log shows the menu built and the setMenu: statement
fires, but the target control does not receive the new menu.

My assumption at the moment is that it is a sequence of loading issue: that the
popup button isn't present yet (?) when
the menu hand off fires.

Here's the relevant selection from the code:

~ Erik




@interface RSTrixieEditor : NSWindowController

@property (retain) IBOutlet NSPopUpButton * actionMenu;

@end


@implementation RSTrixieEditor

@synthesize actionMenu; // popup button

- (id)initWithWindowNibName:(NSString *)windowNibName owner:(id)owner {
self = [super initWithWindowNibName:windowNibName owner:owner];
if (self) {
[self setActionPlugins:[self loadPluginsWithPrefix:@"Action"]];
}
return self;
}


- (void)windowDidLoad
{
[super windowDidLoad];
NSMenu * menu = [[NSMenu alloc] init];

for(RSTrixiePlugin * p in actionPlugins)
{
NSMenuItem * menuItem = [[NSMenuItem alloc] initWithTitle:[p
name] action:@selector(showActionPlugin:) keyEquivalent:@""];
[menuItem setRepresentedObject:p];
[menu addItem:menuItem];
NSLog(@"%s- [%04d] added action menu item for plugin: %@",
__PRETTY_FUNCTION__, __LINE__, [p name]);
}
[actionMenu setMenu:menu];
NSLog(@"%s- [%04d] %@", __PRETTY_FUNCTION__, __LINE__, menu);
// shows description of populated menu
NSLog(@"%s- [%04d] %lu", __PRETTY_FUNCTION__, __LINE__, [[menu
itemArray] count]); // returns 2
NSLog(@"%s- [%04d] %lu", __PRETTY_FUNCTION__, __LINE__, [[[actionMenu
menu] itemArray] count]); // returns 2
NSLog(@"%s- [%04d] %@", __PRETTY_FUNCTION__, __LINE__, [actionMenu
menu]); // (null)
[actionMenu setNeedsDisplay:YES]; // on a whim
}


[â]



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@xxxxxxxxxxxxxxx)

Please 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:
https://lists.apple.com/mailman/options/cocoa-dev/maillists%40codeha.us

This email sent to maillists@xxxxxxxxx
(C)2011 mailinglist-archive.com