Re: NSPopUpButton Problem
Re: NSPopUpButton Problem
- Subject: Re: NSPopUpButton Problem
- From: email@hidden
- Date: Sat, 14 Jul 2001 21:17:36 +0200
Le samedi 14 juillet 2001, ` 01:18, Mark T <email@hidden> a icrit :
I'm having a little bit or trouble with NSPopUpButton's
addItemWithTitle method. Either it's not implemented correctly or I'm
not using it correctly. In the code below, the first time that the
method is called, it seems to work appropriately. j is updated from 0
to 1 and setEnabled works correctly. The second time through the
loop, however, j is not incremented from 1 to 2 and itemAtIndex
crashes the program with the errors following the code snippet. Am I
doing something wrong, or is this method broken?
Mark T.
theButton = [self aPopUpButtonMadeInInterfaceBuilder];
[theButton setAutoenablesItems:NO];
[theButton removeAllItems];
j = [[theButton itemArray] count]; //for debugging purposes only
for(i = 0; i < NUMBER_OF_VARIABLES; i++)
{[theButton addItemWithTitle:@"Disabled Item"];
j = [[theButton itemArray] count]; //for debugging purposes only
[[theButton itemAtIndex:i] setEnabled:NO];}
*** Assertion failure in -[NSMenu itemAtIndex:], NSMenu.m:552
An uncaught exception was raised
Invalid parameter not satisfying: (index >= 0) && (index < [_itemArray
count])
*** Uncaught exception: <NSInternalInconsistencyException> Invalid
parameter not satisfying: (index >= 0) && (index < [_itemArray count]
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
********************** email@hidden
The Commandant Project:
http://lachand.free.fr/
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.