• 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
Cant set state of NSMenuItems attached to NSSearchField
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cant set state of NSMenuItems attached to NSSearchField


  • Subject: Cant set state of NSMenuItems attached to NSSearchField
  • From: "Mike Chambers" <email@hidden>
  • Date: Sun, 30 Nov 2008 11:03:45 -0800

I have an NSMenu attached to an NSSearchField as a searchMenuTemplate.

The menu is as Follows:

-------
All
Start
End
Country
Station
Notes
Frequency
--------

If the user selects "All", I want to remove all check marks from other
selected menu items. If the user selects anything except "All", then I
want to remove the check from the All menu item. In order to allow
this, I have outlets set for each menu item so I can change its state:

----------
	IBOutlet NSMenuItem *allMenuItem;
	IBOutlet NSMenuItem *startMenuItem;
	IBOutlet NSMenuItem *endMenuItem;
	IBOutlet NSMenuItem *countryMenuItem;
	IBOutlet NSMenuItem *stationMenuItem;
	IBOutlet NSMenuItem *notesMenuItem;
	IBOutlet NSMenuItem *frequenciesMenuItem;
----------

This seems like it would be easy to implement, but I cant seem to set
the state on a menu item via the IBOutlet reference (and I have triple
checked that the outlets are set correctly, and the debugger seems to
confirm this). I can only set the state in response to the action of
the item being clicked.

------------
-(IBAction)handleSearchMenuItems:(NSMenuItem *)menuItem
{
	NSLog(@"Search");

	NSInteger state = [menuItem state];

	if(state == NSOffState)
	{
		[menuItem setState:NSOnState];
		[allMenuItem setState:NSOffState];
	}
	else
	{
		[menuItem setState:NSOffState];
	}
}

-(IBAction)handleSearchAllItems:(NSMenuItem *)allMenuItemSender
{
	NSInteger state = [allMenuItemSender state];

	if(state == NSOffState)
	{
		[allMenuItemSender setState:NSOnState];

		[startMenuItem setState:NSOffState];
		[endMenuItem setState:NSOffState];
		[countryMenuItem setState:NSOffState];
		[stationMenuItem setState:NSOffState];
		[notesMenuItem setState:NSOffState];
		[frequenciesMenuItem setState:NSOffState];
	}
	else
	{
		[allMenuItemSender setState:NSOffState];
	}
}
------------

So, in the code above, I can set the state for allMenuItemSender and
menuItem, but not for the NSMenuItems which were not clicked.

Again, this seems like it should be simple, but I am completely
stumped (I am pretty new to Cocoa).

Does anyone have any idea of what might be going on?

mike
_______________________________________________

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

  • Follow-Ups:
    • Re: Cant set state of NSMenuItems attached to NSSearchField
      • From: Jim Correia <email@hidden>
  • Prev by Date: Command-clicking table column
  • Next by Date: Re: Cant set state of NSMenuItems attached to NSSearchField
  • Previous by thread: Re: Command-clicking table column
  • Next by thread: Re: Cant set state of NSMenuItems attached to NSSearchField
  • Index(es):
    • Date
    • Thread