Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect UISearchBar focus on the text field

Is there a way to detect if a user has click on the searchbar textfield and the keyboard has appear ?

like image 767
k4. Avatar asked Jan 19 '10 18:01

k4.


3 Answers

From the docs,

  • searchBarTextDidBeginEditing:
  • searchBarCancelButtonClicked:
like image 69
SK9 Avatar answered Nov 12 '22 04:11

SK9


If you are implementing UISearchBarDelegate, the first method that should be called is:

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {  
    //do stuff
    return YES;  
}  

Here's the class reference:

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UISearchBarDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UISearchBarDelegate/searchBarShouldBeginEditing:

like image 42
shawnwall Avatar answered Nov 12 '22 05:11

shawnwall


Your searchbar delegate should receive a searchBarTextDidBeginEditing: message.

like image 35
Ben Gottlieb Avatar answered Nov 12 '22 06:11

Ben Gottlieb