PDA

View Full Version : Can't enable menu item (Preferences...) why?




Xino
Sep 23, 2008, 06:25 AM
I've created a project and created two windows (main window and preferences window). In the menu i've a menu item called "preferences..." and the goal purpose is when I click on the menu item, the window preferences opens.

The problem is that I can't enable the menu item, it remains disable even when I add an action and assign it to the menu item via Interface Builder. I've read some pages on the internet describing how to enable a menu item; simply by assign the menu item to an action... why isn't it working then?

I've added the action to the Application class and exported the class files into my Xcode project.

Thanks for your help :)



whooleytoo
Sep 23, 2008, 09:40 AM
That sounds right, presumably you've saved the project in IB before rebuilding?

Can't think of anything wrong, feel free to post the project up here if you want us to take a look at it. (By the sounds of it, you don't have enough done yet that we can steal! ;) )

kainjow
Sep 23, 2008, 10:17 AM
I've added the action to the Application class and exported the class files into my Xcode project.

My guess is this is your problem. You have added the IBAction methods to an NSApplication subclass, and then in IB you've connected the menu item's action to File Owner, which you may or may not have set as your NSApplication subclass. However, this won't work because File Owner in MainMenu.nib doesn't become the class you assign it. It's always the class that is set in Info.plist PrincipleClass, which unless you've changed it, is NSApplication.

The proper way of connecting menu items is through an application controller object that is created separately in the nib. Subclass NSObject, add your actions there, and create it in the nib and connect it to the menu items.