JeffN
JeffN

Reputation: 1605

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.

Upvotes: 0

Views: 693

Answers (2)

LE SANG
LE SANG

Reputation: 11005

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

Upvotes: 1

ToMfromTO
ToMfromTO

Reputation: 325

  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.

Upvotes: 1

Related Questions