NSSearchField problem
NSSearchField problem
- Subject: NSSearchField problem
- From: Michael de Haan <email@hidden>
- Date: Sat, 12 Oct 2013 18:21:47 -0700
Hi all
I am struggling to solve this problem.
I wish to implement a searchField similar to the "Find" of Xcode's IDE editor, where, for example, "Recent Results" places the item chose into the SearchField and performs the search with the chosen string. The current setup( in OSx) is a simple TableView, an Array controller which populates the tableView with Managed Object instances, and works as expected. ( ie Add, Remove are implemented through the controller).
I have implemented the direct search by creating a predicate with the inputString of the searchField and applying that to the arrayController, which works as expected. (done in the delegate ControlTextDidChange method);
The code I am using to try to implement the issue mentioned above is as follows. (unapologetically "modified" from Apple's searchField example)
-(void)setUpSearchField{
if ([self.searchField respondsToSelector:@selector(setRecentSearches:)]) {
NSMenu * searchMenu = [[NSMenu alloc]initWithTitle:@"Search Menu"];
[searchMenu setAutoenablesItems:YES];
NSMenuItem * recentSearchesItem = [[NSMenuItem alloc]initWithTitle:@"Recent Names"
action:@selector(searchWithRecentNames:)
keyEquivalent:@""];
[recentSearchesItem setTarget:self];
[recentSearchesItem setTag:NSSearchFieldRecentsMenuItemTag];
[searchMenu insertItem:recentSearchesItem atIndex:0];
id searchCell = [self.searchField cell];
[searchCell setSearchMenuTemplate:searchMenu];
}
}
The selector( ie (searchWithRecentNames:) is never called. I do note that if the tag "NSSearchFieldRecentsMenuItemTag" is omitted, it is called, but that is not following the example as suggested by Apple in their SearchField example.
I have tried the following delegate method.
control:textDidChange....which, I learnt is only called with a user interaction.
I realize that the other delegate methods tried are all under the heading of "TextField" or "Control" delegate methods, but with equal luck.
Clearly, what I **think** I need is a delegate method that is triggered when the "recent searches" string is selected and clicked, but that is eluding me.
A pointer in the right direction would be greatly appreciated.
Thanks in advance.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden