【问题标题】:how to activate a UISearchDisplayController with pre-set term?如何使用预设期限激活 UISearchDisplayController?
【发布时间】:2012-03-08 04:09:59
【问题描述】:

我正在以一种非常规的方式使用 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 继续显示它的灰色覆盖,我该如何清除它?

【问题讨论】:

    标签: ios uisearchdisplaycontroller


    【解决方案1】:

    更改调用顺序似乎可以解决问题。不知道为什么。

    [self.searchDisplayController setActive: YES animated: YES]; 
     self.searchDisplayController.searchBar.hidden = NO;
    self.searchDisplayController.searchBar.text = @"term";
    [self.searchDisplayController.searchBar becomeFirstResponder]; 
    

    【讨论】:

    • 感谢您的提示,我遇到了同样的问题。仍然有一个问题:当文本为空时,我无法让 searchResultsTableView 出现,我必须做 self.searchDisplayController.searchBar.text = @" " 这有点 hacky.. 如果有人有更好的建议,请让我知道!这应该是可能的,因为移动 Safari 中的 Google 搜索完全一样。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    相关资源
    最近更新 更多