简体   繁体   English

搜索显示控制器是否可以在搜索文本字段为空时隐藏取消按钮?

[英]Search display controller prevent hiding the cancel button if the search text field is empty?

I have search display controller and I want the cancel button to be always visible , I set the option of " shows the cancel button " from the interface builder " xib file" and I handled the delegate of 我有搜索显示控制器,我希望取消按钮始终可见,我在界面构建器“ xib文件”中设置了“ 显示取消按钮 ”选项,并处理了

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller 
{
    controller.searchBar.showsCancelButton = YES;
}

to make the cancel button always shown , it works correct if the search text input has text , but if I did not enter any text in the search bar and click on the faded view the search textfield stop editing this is correct behavior but it hides the cancel button so how i can make the cancel button always shown ? 为了使取消按钮始终显示,如果搜索文本输入中包含文本,则它可以正常工作,但是如果我没有在搜索栏中输入任何文本并单击褪色的视图,则搜索文本字段会停止编辑,这是正确的行为,但是它隐藏了取消按钮,以便使取消按钮始终显示?

    self.searchDisplayController.delegate=self;
self.searchDisplayController.searchResultsDelegate=self;
self.searchDisplayController.searchBar.delegate=self;

and in begin search 并开始搜索

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller 
{
    [self.searchDisplayController.searchBar setShowsCancelButton:YES animated:NO];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM