问题
I'm going to look silly again, but it's better than getting crazy! Here's my issue. I have a UISearchBar which has a scopeBar that I want to hide. I do this :
searchBar.showsScopeBar = NO;
and I also call the
[searchBar becomeFirstResponder];
method at the end of the function, but it doesn't work.
Any idea ?
Thanks
回答1:
Okay, for those having the same issue, to hide a scopeBar, you actually need to set the scopeButtonTitles property to nil :
searchbar.scopeButtonTitles = nil;
and set them programatically when you want to show the scopeBar :
searchbar.scopeButtonTitles = [NSArray arrayWithObject:@"Button 1", @"Button 2",...,nil];
That works. The showsScopeBar property has to be true.
searchBar.showsScopeBar = YES;
回答2:
Another way of doing this is through the IB. If you had clicked the scope button and then unchecked it, the scope titles will still remain. Which means it will always pop up when a user enters the searchbar. Just select the 2 scope titles and delete them. Voila, it won't pop up again.
来源:https://stackoverflow.com/questions/3954007/iphone-hide-a-scopebar-from-a-searchbar