Re: Turning NSMenuItem into separator
Re: Turning NSMenuItem into separator
- Subject: Re: Turning NSMenuItem into separator
- From: Andy Lee <email@hidden>
- Date: Fri, 30 Sep 2005 01:34:29 -0400
On Sep 29, 2005, at 8:51 PM, Thom McGrath wrote:
I'm building a dynamic menu using
- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:
(int)index shouldCancel:(BOOL)shouldCancel
- (int)numberOfItemsInMenu:(NSMenu *)menu
in a menu delegate. So far, everything is working well. Much easier
than REALbasic :P - but I'm running into an issue. I need one of
the items to be a separator. The only way I can see to do that is
to create a new NSMenuItem. But I'm already handed a menu item to
use. I've tried releasing it and creating a new one in it's place,
but nothing is working and not crashing.
You shouldn't release the menu item, since you didn't allocate it.
How about doing the following in your -
menu:updateItem:atIndex:shouldCancel: method?
if (index == 3) // or whatever
{
[menu removeItemAtIndex:index];
[menu insertItem:[NSMenuItem separatorItem] atIndex:index];
}
From a very quick test it seems to work, but I don't know if there
could be problems modifying the menu midstream like this.
On Sep 29, 2005, at 11:03 PM, Andreas Mayer wrote:
Try this one:
- (void)_configureAsSeparatorItem;
Beware: This method is private. You should test with -
respondsToSelector: first.
Bummer that there isn't a public method for this. Perhaps Thom could
file a radar asking for one?
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden