iPhone : hide a scopeBar from a searchBar

耗尽温柔 提交于 2019-12-23 21:38:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!