UISearchBar Dismiss Method

For a UISearchBar with UISearchDisplayController, when the searchfield is clicked, the keyboard appears and an overlay shows over the tableview. When cancel is clicked

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

is called.

I am wondering if there is a method called when the overlay is clicked. It does dismiss the keyboard and go back to the tableview. Basically I want to make clicking this overlay run the same method as when cancel is clicked. Any ideas? I checked the Apple Docs and couldn't find anything other than the cancel button method.


  • You can subclass UISearchDisplayController and call this cancel method from touchesBegan method:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    
  • You can assign the UITapGestureRecognizer to the overlayView.


  • *CANCEL : just [self.searchDisplayController setActive:NO]; and implement it inside touchesBegan like ToMfromTO's answer.

    链接地址: http://www.djcxy.com/p/44292.html

    上一篇: 解除键盘FirstResponder问题

    下一篇: UISearchBar关闭方法