0

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.

JeffN
  • 1,575
  • 15
  • 26

2 Answers2

1

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

LE SANG
  • 10,955
  • 7
  • 59
  • 78
  • But do you know what method is called when you just click away from the uisearchbar without clicking cancel? It does dismiss the searchbar and keyboard, but I need it to run another method as well – JeffN Feb 05 '13 at 00:12
1
  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.

ToMfromTO
  • 325
  • 1
  • 4