I have an NSSearchField control where I want to show a few categories that are to appear as a menu when the user clicks on the arrow to the left. After reading Apple's documentation, I have gotten some idea. The following is my code.
// .h
@interface AppDelegate : NSObject {
IBOutlet NSSearchField *searchField;
}
// .m
- (void)awakeFromNib {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:[self window]];
[window setContentBorderThickness:22.0 forEdge:NSMinYEdge];
NSMenu *cellMenu = [[NSMenu alloc] initWithTitle:NSLocalizedString(@"Search Menu",@"Search Menu title")];
NSMenuItem *item;
item = [[NSMenuItem alloc] initWithTitle:@"Title" action:@selector(setSearchCategoryFrom:) keyEquivalent:@""];
[item setTarget:self];
[item setTag:1];
[cellMenu insertItem:item atIndex:0];
item = [[NSMenuItem alloc] initWithTitle:@"Username" action:@selector(setSearchCategoryFrom:) keyEquivalent:@""];
[item setTarget:self];
[item setTag:2];
[cellMenu insertItem:item atIndex:1];
id searchCell = [searchField cell];
[searchCell setSearchMenuTemplate:cellMenu];
}
- (IBAction)setSearchCategoryFrom:(NSMenuItem *)menuItem {
if ([menuItem tag] == 0) {
}
else {
}
}
And the screenshot below shows the result. Now, I need to set the state of selection, whichever they choose, to 1 so that a checkmark will appear. How do I do that?
Thank you for your help.