我正在以一种稍微非常规的方式使用 UISearchViewController。
我的 UISearchBar 最初是隐藏的。当用户点击按钮时,我取消隐藏 UISearchBar 并激活 UISearchViewController。我还设置了搜索栏的文本,并告诉搜索栏成为第一响应者。
问题是 UISearchDisplayController 创建的灰色叠加层仍然可见。它不会消失,除非我预设的文本被清除,并且用户开始重新输入。
self.searchDisplayController.searchBar.hidden = NO;
self.searchDisplayController.searchBar.text = @"term";
[self.searchDisplayController.searchBar becomeFirstResponder]; // this actually appears to activate everything
[self.searchDisplayController setActive: YES animated: YES]; // this activates but does not set the searchbar to 1st responder...
为什么 UISearchDisplayController 继续显示它的灰色覆盖层,我该如何清除它?
最佳答案
更改调用顺序似乎可以解决问题。不知道为什么。
[self.searchDisplayController setActive: YES animated: YES];
self.searchDisplayController.searchBar.hidden = NO;
self.searchDisplayController.searchBar.text = @"term";
[self.searchDisplayController.searchBar becomeFirstResponder];
关于ios - 如何激活具有预设期限的 UISearchDisplayController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9608051/