【问题标题】:UISearchBar Dismiss MethodUISearchBar 关闭方法
【发布时间】:2013-02-05 08:36:50
【问题描述】:

对于带有 UISearchDisplayController 的 UISearchBar,当单击搜索字段时,会出现键盘并在 tableview 上显示覆盖。点击取消时

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

被调用。

我想知道单击叠加层时是否调用了一个方法。它确实关闭了键盘并返回到 tableview。基本上我想让单击此叠加层运行与单击取消时相同的方法。有任何想法吗?我检查了 Apple Docs,除了取消按钮方法之外找不到其他任何东西。

【问题讨论】:

    标签: ios uisearchbar uisearchbardelegate


    【解决方案1】:
    1. 您可以继承 UISearchDisplayController 并从touchesBegan method 调用此取消方法:

      - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
      
    2. 您可以将UITapGestureRecognizer 分配给overlayView。

    【讨论】:

      【解决方案2】:

      *CANCEL : 只是 [self.searchDisplayController setActive:NO];并在 touchesBegan 中实现它,就像 ToMfromTO 的回答一样。

      【讨论】:

      • 但是你知道当你点击离开uisearchbar而不点击取消时调用的是什么方法吗?它确实关闭了搜索栏和键盘,但我还需要它来运行另一种方法
      猜你喜欢
      • 2010-11-21
      • 1970-01-01
      • 2016-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-02
      • 1970-01-01
      • 2019-05-04
      相关资源
      最近更新 更多