Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Enabling MenuItems

Enabling MenuItems
Thread Tools
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status: Offline
Reply With Quote
May 19, 2002, 01:40 PM
 
I have just started Cocoa programming and I have a problem. I have three MenuItems in my program that need to be enabled at certain times. Two of the MenuItems work perfectly. They are enabled and disabled fine with [menu setEnabled:...];. However, the third MenuItem doesn't listen and is always enabled no matter what I do. What do I have to do to change whetter it is enabled? Something with validateMenuItem? Please help...
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
May 19, 2002, 06:55 PM
 
The runtime sends a - (BOOL)validateMenuItem NSMenuItem *)anItem
up the responder chain. Implement this in the view or control or whatever you've got in the front window, have it check to see whether the item should be enabled and return YES or NO.
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
seppak  (op)
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status: Offline
Reply With Quote
May 19, 2002, 08:07 PM
 
Ok, I did that and everything works. I printed the selector that was connected to the menuItem when validateMenuItem was called. Only the menuItem I was having trouble with is ever called. Why aren't the other menuItems asked validateMenuItem?
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
May 20, 2002, 09:45 AM
 
I don't know why the other menu items aren't called by the validateMenuItem method. I have the exact same problem and I have yet to find a way to get it to work.

The file menu in my app actually stopped going through validateMenuItem after I added a new item to it in IB. I couldn't figure out what was going wrong; all of the connections were there in IB. I ended up deleting the File menu in IB and putting in a new one and then it worked again. But as soon as I added the new menu item, it stopped getting called through validateMenuItem in my controller class. Is this a bug?
     
seppak  (op)
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status: Offline
Reply With Quote
May 20, 2002, 03:35 PM
 
This is definitely getting foggy....You enable menu items by using setEnabled:...this works for most items but some just call validateMenuitem randomly...I have this in validateMenuItem:
NSLog(@"AppController: ValidateMenuItem Method Called: %@", NSStringFromSelector([menuItem action]));

It is only ever called with the action showPreferences:...All of the other menuItems never call this...Someone clear this up for me.
     
Fresh-Faced Recruit
Join Date: May 2002
Location: Ft Lauderdale
Status: Offline
Reply With Quote
May 20, 2002, 11:32 PM
 
Interesting. I ran into this same problem today. I implemented validateMenuItem and all was well. Seems strange to have to do that though.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:02 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2