CocoaDev

Edit AllPages

See also NSMenuItemCategory. – DustinVoss

Header file for NSMenuCategory+CocoaDevUsersAdditions:

#import <AppKit/NSMenu.h>

@interface NSMenu (CocoaDevUsersAdditions)

Implementation file for NSMenuCategory+CocoaDevUsersAdditions:

#import “NSMenuCategory+CocoaDevUsersAdditions.h”

@implementation NSMenu (CocoaDevUsersAdditions)

// Added 20 August 04. Sets aMenuItem to NSOnState (checked), // and turns the rest of the items off. -(void)setSelectedItem:(NSMenuItem *)aMenuItem { NSArray *myItems = [self itemArray]; NSEnumerator *itemEnumerator = [myItems objectEnumerator]; NSMenuItem *eachItem = nil;

while (eachItem = [itemEnumerator nextObject]) { [eachItem setState:([eachItem isEqual:aMenuItem] ? NSOnState : NSOffState)]; // isEqual: is not guaranteed to return [[NSOnState if it’s true } }

@end

The NSMenuItem protocol is now deprecated, edited all id to NSMenuItem*.

Category:CocoaDevUsersAdditions