【问题标题】:Search display controller prevent hiding the cancel button if the search text field is empty?如果搜索文本字段为空,搜索显示控制器会阻止隐藏取消按钮吗?
【发布时间】:2012-05-15 21:13:58
【问题描述】:
我有搜索显示控制器,我希望取消按钮始终可见,我从界面构建器“xib”中设置了“显示取消按钮”选项文件”,我处理了
的代表
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.searchBar.showsCancelButton = YES;
}
要使取消按钮始终显示,如果搜索文本输入有文本,它会正常工作,但如果我没有在搜索栏中输入任何文本并单击褪色视图搜索文本字段停止编辑这是正确的行为但是它隐藏了取消按钮,所以我怎样才能让取消按钮始终显示?
【问题讨论】:
标签:
iphone
objective-c
ios
【解决方案1】:
self.searchDisplayController.delegate=self;
self.searchDisplayController.searchResultsDelegate=self;
self.searchDisplayController.searchBar.delegate=self;
开始搜索
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[self.searchDisplayController.searchBar setShowsCancelButton:YES animated:NO];
}