0
votes

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.

2

2 Answers

1
votes
  1. You can subclass UISearchDisplayController and call this cancel method from touchesBegan method:

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

1
votes

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