• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSPopUpButton Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSPopUpButton Problem


  • Subject: Re: NSPopUpButton Problem
  • From: j o a r <email@hidden>
  • Date: Sat, 14 Jul 2001 12:40:17 +0200

On fredag, juli 13, 2001, at 10:10 , Mark T wrote:

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?

I think that the code looks OK. I use basically the same code, but without the loop, since I have all the items to add in an array:

/*
// Given these objects
NSPopUpButton *myPopUpButton;
NSArray *myArrayOfItems;
NSString *mySelectedItem;
*/

// Remove all items in the menu
[myPopUpButton removeAllItems];

// Add all items
[myPopUpButton addItemsWithTitles:myArrayOfItems];

// Switch menu selection to new selected item
[myPopUpButton selectItemWithTitle:mySelectedItem];

You could perhaps try this way of doing the same thing? If you still want to use a loop, you might consider using NSEnumerator:s since they might protect you from venturing outside of the loop:

// Remove all items in the menu
[myPopUpButton removeAllItems];

// Add all items
{
NSEnumerator *itemEnumerator = [myArrayOfItems objectEnumerator];
NSString *thisItem;

while (thisItem = [itemEnumerator nextObject]) {
[myPopUpButton addItemWithTitle: thisItem];
}
}

// Switch menu selection to new selected item
[myPopUpButton selectItemWithTitle:mySelectedItem];


Regards,

j o a r


References: 
 >NSPopUpButton Problem (From: Mark T <email@hidden>)

  • Prev by Date: Frameworks and global variables
  • Next by Date: Fwd: Saving TIFF
  • Previous by thread: NSPopUpButton Problem
  • Next by thread: Re: NSString, NSArray, get the characters of one of the NSString in an Array of NSStrings?
  • Index(es):
    • Date
    • Thread