Re: setting menuitem state...
Re: setting menuitem state...
- Subject: Re: setting menuitem state...
- From: "Louis C. Sacha" <email@hidden>
- Date: Mon, 26 Jan 2004 21:03:47 -0800
Hello...
The simple answer:
When you say
if ([tempDict valueForKey:@"status"]) {...}
the message is returning the object that was stored in the dictionary
for the key @"status". It will evaluate to TRUE (YES) if there was
any object stored for that key, and FALSE if the result of the
message was nil which means there was no object stored for that key.
What you probably want to say (assuming the object is a NSNumber
instance containing a BOOL value) is
if ([[tempDict valueForKey:@"status"] boolValue]) {...}
That should work for most implementations (where you know for sure
that the object is an NSNumber containing a boolean value). There are
some subtle issues if you don't have control over the dictionary, and
the object might not be NSNumber or might contain something other
than a boolean (search the archives from the last few days for
"boolValue" and it should pull up a message where someone else
explained that in more detail, and if you're not even sure what kind
of object might be returned then you would need to check before
sending the boolValue message).
Hope that helps,
Louis
ok so this is supposed to let the user turn on or off multiple items in
the popupbutton menu but even if status is NO it doesn't set the menu
item to NSOffState...i can't figure out why i've check it and the item
is a bool set to no but it doesn't work it will set the NSOnState once
then they just stay on?
- (void)menuWillPopUp:(NSNotification *)aNotification;
{
NSMenuItem *item;
NSEnumerator *enumerator = [[nameMenu itemArray] objectEnumerator];
while(item = [enumerator nextObject])
{
if (![item isSeparatorItem])
{
NSMutableDictionary *tempDict =
[NSMutableDictionary dictionary];
[tempDict
addEntriesFromDictionary:[ABFieldsDict valueForKey:[item
title]]];
if ([tempDict valueForKey:@"status"])
{
[[nameMenu itemWithTitle:[item
title]] setState:NSOnState];
}
else
{
[[nameMenu itemWithTitle:[item
title]] setState:NSOffState];
}
}
}
}
_______________________________________________
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.
_______________________________________________
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.