• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSPopUpButton not accepting setMenu: from WindowController code
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSPopUpButton not accepting setMenu: from WindowController code


  • Subject: NSPopUpButton not accepting setMenu: from WindowController code
  • From: Erik Stainsby <email@hidden>
  • Date: Sat, 18 Feb 2012 07:37:02 -0800

[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- [d] added action menu item for plugin: %@", __PRETTY_FUNCTION__, __LINE__, [p name]);
	}
	[actionMenu setMenu:menu];
	NSLog(@"%s- [d] %@", __PRETTY_FUNCTION__, __LINE__, menu);		// shows description of populated menu
	NSLog(@"%s- [d] %lu", __PRETTY_FUNCTION__, __LINE__, [[menu itemArray] count]);		// returns 2
	NSLog(@"%s- [d] %lu", __PRETTY_FUNCTION__, __LINE__, [[[actionMenu menu] itemArray] count]);  // returns 2
	NSLog(@"%s- [d] %@", __PRETTY_FUNCTION__, __LINE__, [actionMenu menu]);  // (null)
	[actionMenu setNeedsDisplay:YES];  // on a whim
}


[…]



_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: NSPopUpButton not accepting setMenu: from WindowController code
      • From: Keary Suska <email@hidden>
  • Prev by Date: Re: __block __weak - am I doing this right?
  • Next by Date: Re: __block __weak - am I doing this right?
  • Previous by thread: Re: My runloop-based async code breaks with GCD
  • Next by thread: Re: NSPopUpButton not accepting setMenu: from WindowController code
  • Index(es):
    • Date
    • Thread