简体   繁体   中英

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?

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]; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM