Re: Application Menu - Preferences
Re: Application Menu - Preferences
- Subject: Re: Application Menu - Preferences
- From: Quincey Morris <email@hidden>
- Date: Wed, 24 Feb 2010 13:39:17 -0800
On Feb 24, 2010, at 12:58, David Blanton wrote:
> What I was really getting at is how to set the target / action for when the item is selected. Here is what I did, so if this is way off base please let me know.
>
> I sub-classed NSMenuItem and set the Preferences menu item to this class.
>
> In the awakeFromNib I set the target and action.
>
> Am I doing too much? Is there a 'less code' approach?
Maybe I'm missing a detail of your requirements, but this seems like the hard way.
Simply set the Preferences menu item target to First Responder (i.e. nil) and its action to a method name of your choosing. Implement that method in your application delegate. The action travels up the responder chain to the application and then finally to the application delegate, where your method will be found.
Your application delegate can then do whatever is necessary to display the preferences (such as creating a window controller the first time, and telling it to display the window).
Note: Paul suggested a slightly different way, connecting the action to something in the NIB file. That works fine too, but the drawback with such an approach is that you have to load up your main menu NIB file with additional windows and views. It seems cleaner to me to put the preferences window in a separate NIB and have the app delegate create the window controller that loads the separate NIB.
_______________________________________________
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