searchBar 方法总结

点击searchBar的输入区域,就会依次触发

2、- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar    // return NO to not become first responder

3、- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar  // called when text starts editing

4、- (void) searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller   // when we start/end showing the search UI

此时,search UI就会全屏显示出来,键盘也弹起了

5、- ( void ) searchDisplayControllerDidBeginSearch:( UISearchDisplayController  *)controller

点击键盘上的一个按钮

6、- (BOOL)searchBar:(UISearchBar *)searchBar   shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text  // called before text changes

再点击键盘上的一个按钮,仍然调用step6的方法;再点击键盘上的一个按钮,仍然调用step6的方法,这时候可以选中一个汉字,就会触发

7、- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText     //called when text changes (including clear)

8、- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString    // return YES to reload table. called when search string/option changes. convenience methods on top UISearchBar delegate methods

9、- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView     //called when table is shown/hidden

10、- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView

此时就会显示搜索结果,再输入,会重复step6-8

如果此时点击键盘上的“搜索”按钮,会触发

11、- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar    // called when keyboard search button pressed

12、- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar   // return NO to not resign first responder

13、- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar   // called when text ends editing

这时UISearchBar中的文字输入框会失去焦点,键盘就会消失

如果此时点击UISearchBar文字输入框最右边的x来清除输入的话,会触发step7、8以及

14、- (void)searchDisplayController:(UISearchDisplayController *)controller willHideSearchResultsTableView:(UITableView *)tableView

15、- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView

又开始调用step2、3,界面看起来就像刚才进入search UI全屏界面时的样子,可以再次重复以上操作

当然,可以点击右上角的“取消/cancel”按钮,就会触发

16、- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar   //called when cancel button pressed

17、- (void) searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller

18、- (void)searchDisplayController:(UISearchDisplayController *)controller willHideSearchResultsTableView:(UITableView *)tableView

19、- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView

20、- (void)searchDisplayController:(UISearchDisplayController *)controller willUnloadSearchResultsTableView:(UITableView *)tableView

21、- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值