• 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: can't read NSMenuItem titles from NSMenu's below first NSMenu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: can't read NSMenuItem titles from NSMenu's below first NSMenu


  • Subject: Re: can't read NSMenuItem titles from NSMenu's below first NSMenu
  • From: Graham Cox <email@hidden>
  • Date: Fri, 13 Nov 2009 16:38:20 +1100

On 13/11/2009, at 2:09 PM, SRD wrote:

> When selecting anything off the first menu (item-2 or item-3), the
> value of 'sender' prints fine and I can compare it using the code
> below. But if I select the first item which is an NSMenu and leads to
> another NSMenu with it's item (item-1), then the method menuReader: is
> called, but sender does not hold any value at all, it's just blank.
>
> Anyone understand what I'm doing wrong here?
>
> - (IBAction) menuReader:(id) sender
> {
>    NSLog(@"sender %@", [sender titleOfSelectedItem]);
>
> 	if ([[sender titleOfSelectedItem] isEqualToString:@"item1"]) {
> 		// ...
> 	}
> 	else if ([[sender titleOfSelectedItem] isEqualToString:@"item2"]) {
> 		// ...
> 	}
> 	else if ([[sender titleOfSelectedItem] isEqualToString:@"item3"]) {
> 		// ...
> 	}
> }
>
> Any help much appreciated.


You are calling [sender titleOfSelectedItem], but for the submenu, the sender isn't the pop-up button so it doesn't respond to that message. Why not log what the sender actually is, and you'll see what's going on:

NSLog(@"sender: %@", sender);

--Graham


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >can't read NSMenuItem titles from NSMenu's below first NSMenu (From: SRD <email@hidden>)

  • Prev by Date: can't read NSMenuItem titles from NSMenu's below first NSMenu
  • Next by Date: Re: Auto-scrolling view
  • Previous by thread: can't read NSMenuItem titles from NSMenu's below first NSMenu
  • Next by thread: How to update table while in a method
  • Index(es):
    • Date
    • Thread