• 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: Creating Menu Items from NSMutableArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating Menu Items from NSMutableArray


  • Subject: Re: Creating Menu Items from NSMutableArray
  • From: Jeremy Dronfield <email@hidden>
  • Date: Thu, 15 Aug 2002 22:43:25 +0100

On Thursday, August 15, 2002, at 09:57 pm, Ryan Hale wrote:

In my Cocoa app I would like to add items to a submenu for each "record" in an NSMutableArray. For example: it the user has added the title "Work Sig" to the record, I want my submenu to show "Work Sig" as an item.

This is all I need for now, but I eventually (i.e. this weekend:) ) want the menu item to invoke an action that inserts the value for the record, so in the previous example it would insert the users Work Signature. Right now I have a MutableArray and a dictionary for each "item" (Name and then Text).

The following should work, though I haven't tried it so can't vouch for it. If you mean that your array is an array of dictionaries, then you'll have to add code to extract the title you want to use from each object.

int index;
for (index = 0; index < [myArray count]; index++) {
NSMenuItem *newItem;
newItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:[myArray objectAtIndex:index] action:NULL keyEquivalent:@""];
[newItem setTarget:self];
[newItem setAction:@selector(myAction:)];
[myMenu addItem:newItem];
[newItem release];
}

Hope it helps.
-Jeremy

=======================================
email@hidden // email@hidden
The Alchemy Pages:
- fractious fiction at http://freespace.virgin.net/jeremy.dronfield
_______________________________________________
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.

References: 
 >Creating Menu Items from NSMutableArray (From: Ryan Hale <email@hidden>)

  • Prev by Date: Event handling in cocoa
  • Next by Date: killing NSThreads
  • Previous by thread: Creating Menu Items from NSMutableArray
  • Next by thread: Re: Creating Menu Items from NSMutableArray
  • Index(es):
    • Date
    • Thread