Re: NSPopUpButton Problem
Re: NSPopUpButton Problem
- Subject: Re: NSPopUpButton Problem
- From: Mark T <email@hidden>
- Date: Sat, 14 Jul 2001 15:55:58 -0400
I'm pretty sure that Cocoa doesn't allow you to put two items with
the same title in a menu. This makes perfect sense from a user
interface point of view.
So I guess that [theButton addItemWithTitle:@"Disabled Item"] is
only executed once, hence j does not grow past 1, and the exception
occurs for i = 1.
I suspect you don't really want a menu full of identical items, do you?
Thomas Lachand-Robert
This seems to be correct. When I changed the loops to add a
differently named item each time, it worked fine. However, I do want
to start with identically named items. As the use changes things in
other parts of the program, the titles of the menu items change to
reflect that and enable themselves. In the end, I solved the problem
by using the following loop, which uses different names when adding
the item, then immediately changes them to the same string:
for(i = 0; i < NUMBER_OF_VARIABLES; i++)
{[theButton insertItemWithTitle:[NSString
stringWithFormat:@"%d",i] atIndex:i];
[[theButton itemAtIndex:i] setTitle:@"Disabled"];
[[theButton itemAtIndex:i] setEnabled:NO];}
I feel that Apple's documentation could be updated to reflect that
you can't add a menu item with the same name as another menu item,
especially since you can later change them to the same title.
Mark T.