所以当我点击搜索栏时,我试图阻止取消按钮出现。我试过这个 -
[self.searchDisplayController.searchBar setShowsCancelButton: NO animated:NO];
NSLog(@"CANCEL BUTTON : %hhd", self.searchDisplayController.searchBar.showsCancelButton);
并且日志告诉我showsCancelButton
的值为0
,表示它已关闭。
那是怎么回事?
答案 0 :(得分:2)
您可以在“searchDisplayControllerWillBeginSearch”委托方法中设置取消按钮以隐藏,例如:
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
controller.searchBar.showsCancelButton = NO;
}
如果您不使用UISearchDisplayController
,也可以使用以下内容-(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
//This'll Show The cancelButton with Animation
[searchBar setShowsCancelButton:NO animated:YES];
}
答案 1 :(得分:1)
试试这个,
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
searchBar.showsCancelButton = NO;
return YES;
}