Search code examples
objective-cxcodeios5searchbar

iOS 5.x - detecting when user clicked on the search text field


How do I detect when the user pressed the empty text field in a generic search bar?


Solution

  • 1) You should set delegate property of your text field (UITextField or UISearchBar).

    2) The you should implement in delegate following method:

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    

    or

    - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
    

    that will be called whenever user wants to enter text.