ios - 如何激活具有预设期限的 UISearchDisplayController?

标签 ios uisearchdisplaycontroller

我正在以一种稍微非常规的方式使用 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/

相关文章:

ios - 功能执行延迟(请求访问权限后)IOS

ios - 在 uiimageview 中具有边框的着色区域

html/css 在 ios 设备上没有响应

objective-c - 如何抑制虚拟键盘滑入动画?

ios - 让线程进入休眠状态但保持动画继续 - 这可能吗?

ios - UITableViewController 与 UISearchDisplayController 多选同步

ios - 获取碰撞点时遇到问题

iphone - 具有 6.1 部署目标的 iOS 应用程序

ios - 如何搜索字典数组并在 UITableview 中显示?

ios - 我如何使用 UISearchBar 和 UISearchDisplayController