Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Xino

macrumors member
Original poster
Sep 5, 2008
36
0
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

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
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

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.