How to collapse keyboard when cancel search button is clicked?

0

How to collapse the keyboard when the cancel button is clicked on a UISearchBar?

I tried some methods and even delegate methods, but it did not work.

I'll put an image to be more precise:

    
asked by anonymous 04.12.2014 / 05:49

1 answer

2

Use the searchBar delegate to add the cancel button when the user starts typing text:

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{
    [_seachBar resignFirstResponder];
}
-(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar{
    _seachBar.showsCancelButton = NO;
}
-(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{
    _seachBar.showsCancelButton = YES;
}
    
04.12.2014 / 20:31