Search code examples
iphoneipadipod

How i dismiss keyboard on tapping search button on keyboard regarding UISearchBar?


I m developing an application in which i adding one control UISearchBar. When i started editing text in UIsearchBar then keypad is animated on the screen. After i completed my complete editing or canceling all text then i will stuck on point of dismissing keypad. How i dismiss keyboard on tapping search key form UIKeypad?

Also same question for UITextField and UITextView?

Thanks


Solution

  • Make sure the view controller which has the SearchBar implements the SearchBarDelegate and you set the searchBar.delegate to self:

    @interface AddressSearchViewController : UIViewController <UISearchBarDelegate>
    

    then implement the following method:

    -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
    {
        [searchBar resignFirstResponder];
    }
    

    This will make the keyboard disappear when you tap the search button on the keyboard or the search bar