Home > DeveloperSection > Forums > How to dismiss keyboard using UISearchBar in Objective-C?
Alex Leblois
Alex Leblois

Total Post:67

Points:471
Posted on    February-05-2016 1:04 AM

 iPhone iPhone  Objective C  Ipad 
Ratings:


 1 Reply(s)
 409  View(s)
Rate this:

I am using UISearchBar and UITableView in our iPhone application as a contact application. I am using results of searchbar into the uitableview and when I tap on any cell I will move to another view to display details of related item (cell content). I want to dismiss the keyboard when I tap outside the searchbar. So I am using UITapGestureRecognizer to dismiss the keyboard, but now another problem is created with the table cell. When I tap on the table cell to move another view controller its not working?

So please suggest me what to do to solve this issue!

Thank you.



Tarun Kumar

Total Post:213

Points:1635
Supported
Posted on    February-05-2016 2:05 AM

If you want to dismiss the keyboard at the time of using uisearchbar then don't use gesture recognizer if it is not maindatory to recognize something.
UISearchBar already provide the delegate method searchBarTextDidEndEditing: to find the searchbar text editing is end now.
Here is the example of delegate method of UISearchBar and call the method resignFirstResponder on the searchBar reference:
- (void) searchBarTextDidEndEditing:(UISearchBar *)searchBar {
    [self.searchBar resignFirstResponder];
}

Don't want to miss updates? Please click the below button!

Follow MindStick