Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to activate a UISearchDisplayController with pre-set term?

I'm using a UISearchViewController in a slightly non-conventional way.

My UISearchBar is initially hidden. When the user taps a button I unhide the UISearchBar and activate the UISearchViewController. I also set the text of the searchbar, and tell the searchbar to become first responder.

The problem is that the gray overlay created by the UISearchDisplayController remains visible. It doesn't go away unless the text that I preset is cleared, and the user begins typing anew.

    self.searchDisplayController.searchBar.hidden = NO;
    self.searchDisplayController.searchBar.text = @"term";
    [self.searchDisplayController.searchBar becomeFirstResponder]; // this actually appears to activate everything
    [self.searchDisplayController setActive: YES animated: YES]; // this activates but does not set the searchbar to 1st responder...

Why does the UISearchDisplayController continue to show it's gray overlay, and how do I clear it?

like image 471
TomSwift Avatar asked Mar 07 '12 19:03

TomSwift


1 Answers

changing the order of the calls seemed to do the trick. not sure why.

[self.searchDisplayController setActive: YES animated: YES]; 
 self.searchDisplayController.searchBar.hidden = NO;
self.searchDisplayController.searchBar.text = @"term";
[self.searchDisplayController.searchBar becomeFirstResponder]; 
like image 101
TomSwift Avatar answered Nov 15 '22 13:11

TomSwift