Reputation: 1394
Here's my latest problem with the iPhone SDK.
I've got a UISearchBar and its delegate all set up. Also, when I load my view, I call
self.searchDisplayController.searchBar.showsScopeBar = YES;
That way, when my view is first presented, I see the scope bar, as expected. But if touch inside the search bar and then outside it (or even if a perform a search and then cancel it), the scope bar gets hidden again.
So my question is: is it possible to have the scope bar always visible? Even after performing searches?
Thanks a lot.
Upvotes: 7
Views: 5699
Reputation: 9999
I know this is old, but if anyone is still searching for an answer here, this method is working for me with iOS 16. The trick seems to be to set it to false first (?).
extension MyViewController: UISearchControllerDelegate {
func didPresentSearchController(_ searchController: UISearchController) {
searchController.searchBar.showsScopeBar = false
searchController.searchBar.setShowsScope(true, animated: false)
}
func didDismissSearchController(_ searchController: UISearchController) {
searchController.searchBar.showsScopeBar = false
searchController.searchBar.setShowsScope(true, animated: false)
}
}
Upvotes: 0
Reputation: 39512
The UISearchDisplayController is hiding the scope bar for you.
The way around this is to subclass UISearchBar and override the implementation of setShowsScopeBar:
@interface MySearchBar : UISearchBar {
}
@end
@implementation MySearchBar
- (void) setShowsScopeBar:(BOOL) show
{
[super setShowsScopeBar: YES]; // always show!
}
@end
Then, in Interface Builder, change the class of the Search Bar you have in your view (that is associated with the UISearchDisplayController) to the new class type -- MySearchBar in this example.
Upvotes: 10