 |
 |
Enabling MenuItems
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status:
Offline
|
|
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
|
|
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.
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status:
Offline
|
|
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
|
|
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?
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2001
Location: Wisconsin
Status:
Offline
|
|
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
|
|
Interesting. I ran into this same problem today. I implemented validateMenuItem and all was well. Seems strange to have to do that though.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |