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:
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:
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;
}