Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reset a cocoa NSSearchField programmatically?

Tags:

cocoa

I have a simple cocoa user interface with a list of items and a search field, implemented using NSTableView and NSSearchField, respectively. The data source and all of the bindings are set up and working nicely. I see my data in the list, and I can search through it by typing strings in the search field. As I type in more text, the number of items in the list gets smaller and smaller, eventually reduced to the one item I was searching for.

Now, how can I clear the text in the search field and force the list to go back to normal? I can make this happen by clearing the text manually (using the keyboard), but when I try to do it programmatically, the hidden items in the list do not come back.

I'm using this:

[searchField setStringValue:@""];

to clear the text in the search field, but it does not reset the list.

Any ideas? Is there a simple [searchField reset] method that I just can't find in the documentation?

like image 783
e.James Avatar asked Feb 15 '09 03:02

e.James


2 Answers

I figured it out. The following code works:

[searchField setStringValue:@""];
[[[searchField cell] cancelButtonCell] performClick:self];
like image 50
wfarr Avatar answered Sep 22 '22 12:09

wfarr


I figured it out. The following code works:

[searchField setStringValue:@""];
[[[searchField cell] cancelButtonCell] performClick:self];
like image 35
e.James Avatar answered Sep 21 '22 12:09

e.James