【问题标题】:How do I close a UISearchDisplayController programmatically?如何以编程方式关闭 UISearchDisplayController?
【发布时间】:2010-08-23 14:10:43
【问题描述】:

我想在用户单击“搜索”按钮时关闭我的 UISearchDisplayController,因为我正在从网络加载新数据。如何以编程方式关闭控制器?我已经调用了正确的方法,但不知道该怎么做。

我以为下面会起作用,但我错了。

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    [self.searchDisplayController finalize];
}

【问题讨论】:

    标签: iphone ios4 uisearchdisplaycontroller


    【解决方案1】:
    [self.searchDisplayController setActive:NO animated:YES];
    

    享受吧。

    【讨论】:

    • 非常感谢......在 2012 年工作也很棒,也很有帮助 :)
    • 这对我不起作用。我说过一旦用户点击 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {[self.searchDisplayController setActive:NO animated:YES];} 中的某处,但这并没有让它消失。该方法被调用但没有结果。
    • 完美。我在 viewWillDisappear 中使用它。正是我需要的。
    【解决方案2】:

    您需要确保在主线程上将 active 设置为 false:

    dispatch_async(dispatch_get_main_queue(), ^{
        [self.searchDisplayController setActive:NO animated:YES];
    });
    

    【讨论】:

      【解决方案3】:
      func setActive(_ visible: Bool,
        animated animated;: Bool)
      

      如果你使用的是 swift。

      【讨论】:

      • 实际上,对于 Swift 来说,属性是active
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-15
      • 2015-11-26
      • 2020-07-08
      • 2013-07-04
      • 2010-11-17
      相关资源
      最近更新 更多