More NSSearchField menu questions
More NSSearchField menu questions
- Subject: More NSSearchField menu questions
- From: Aaron Patterson <email@hidden>
- Date: Thu, 1 Jan 2004 15:23:19 -0800
I've made my search menu work, /mostly/. It displays the menu, and I can select
an item, and have a check mark displayed next to it.
The problem I'm having is that if I check an item in the list, then type
something in the search field, and hit the "return" key, my menu goes back to
the way the menu was set up when the "setSearchMenuTemplate" call was made.
When I run the sample code I've included, I can check the "Hello World" field,
then type stuff in the search field, and hit the return key. Once I've hit
return, if I examine the menu, "Hello World" is no longer checked. I would
greatly appreciate any insight someone might have. Thanks!
I've zipped up the code and put it here as well:
http://eviladmins.org/~aaron/test_code/TestSearch.tar.gz
--Aaron
- (id)init {
[super init];
return self;
}
- (IBAction)search:(id)sender {
NSLog(@"Search: %@", [sender stringValue]);
}
- (void)awakeFromNib {
NSMenu * cellMenu = [[NSMenu alloc] initWithTitle:@"Search Menu"];
NSMenuItem *item1;
id searchCell = [searchField cell];
item1 = [[NSMenuItem alloc] initWithTitle:@"Hello World!"
action:@selector(testSelector:) keyEquivalent:@""];
[item1 setTarget: self];
[cellMenu insertItem:item1 atIndex:0];
[item1 release];
[searchCell setSearchMenuTemplate:cellMenu];
[cellMenu release];
}
- testSelector:(id)sender {
NSLog(@"Selected item");
if([sender state] == NSOnState) {
[sender setState:NSOffState];
} else {
[sender setState:NSOnState];
}
return self;
}
- (void)dealloc {
[super dealloc];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.