Re: NSPopUpButton Problem
Re: NSPopUpButton Problem
- Subject: Re: NSPopUpButton Problem
- From: tlr <email@hidden>
- Date: Sat, 14 Jul 2001 22:19:51 +0200
Le samedi 14 juillet 2001, ` 09:55, Mark T a icrit :
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.
That's probably written somewhere, since I did not imagine that alone. But
I can't remember where...
May I say that your menu seems to break HID rules? I don't know for your
case, but as a user I would feel very strange facing a menu with items all
the same names! You should give different names if possible. If they
correspond to different actions not currently available, use the names of
the actions. If they are basically "empty slots" (for new documents, etc.)
use number "empty slot 1" etc., and a name more explicit that "disabled"
(which does not give any clue to the user, and is not useful, since the
menu items ARE disabled). You could also just add the menu items when
appropriate, expanding the menu as needed. Just my point of view, though.
Thomas Lachand-Robert
********************** email@hidden
The Commandant Project:
http://lachand.free.fr/
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.