Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Turning NSMenuItem into separator



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Turning NSMenuItem into separator (From: Thom McGrath <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.