Re: NSMenuItem states...
Re: NSMenuItem states...
- Subject: Re: NSMenuItem states...
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 28 Jan 2004 17:30:01 -0800
On Jan 28, 2004, at 2:57 PM, email@hidden wrote:
>
ok so i check a dictionary for the menuitem to see if status is true or
>
false (status is a boolean value in the dictionary)
>
- (void)menuWillPopUp:(NSNotification *)aNotification;
>
{
>
>
NSMenuItem *item;
>
NSEnumerator *enumerator = [[nameMenu itemArray] objectEnumerator];
In general you should use
[aNotification object]
to get the object that sent the notification -- in this case the menu.
(You need to take account of the possibility that there may be more
than one popup...)
>
while(item = [enumerator nextObject])
>
{
>
if (![item isSeparatorItem])
>
{
>
NSDictionary *tempDict = [NSDictionary
>
dictionaryWithDictionary:[ABFieldsDict dictionaryForKey:[item title]]];
>
This doesn't make sense -- you're creating a dictionary using an
existing dictionary; just use the original dictionary directly.
In the longer term it would also be better to use the item's tag rather
than its title, since the title may more readily change (especially if
you're going to localise the app).
>
if([tempDict boolForKey:@"status"])
>
{
>
[[nameMenu itemWithTitle:[item title]] setState:NSOnState];
>
You're iterating through the menu items -- item is already the menu
item whose state you want to set. Just use it directly.
[item setState:NSOnState];
>
}
>
else
>
{
>
[item setState:NSOffState];
>
}
>
}
>
}
>
}
>
>
so what happens is i can select a menuitem which sets the state to true
>
then i can select it again to set it false, but then if i try to select
>
it agin it doesn't appear checked when it pops up next, i've checked
>
the value in the dictionary and it is set to true but then menu just
>
doesn't check again? any suggestions? is my code incorrect i've also
>
tried called menu update but this doesn't seem to help either?
>
I'm afraid it's not clear exactly what you're trying to achieve, but
here's a project that implements what you have above and works
consistently (the attachment will obviously get stripped out on the
list copy).
mmalc
[demime 0.98b removed an attachment of type application/zip which had a name of CheckMenu.zip]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.