How to collect keyboard when cancel search button is clicked?

Asked

Viewed 289 times

0

How to collect the keyboard when the cancel button is clicked on a Uisearchbar?

I tried some methods and even the delegate’s methods, but it didn’t work.

I’ll put up an image to be more precise:

inserir a descrição da imagem aqui

I need that when the cancel button (button with X) is clicked/selected it collects the keyboard.

  • 1

    You may be able to do this, but that’s not the function of this button. The button with X is to clear the typed text. It would be better if you use the cancel button itself than UISearchBar makes available: searchBar.showsCancelButton = YES;

  • Thanks for the clarification. I thought I saw this function in some other app.

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;
}
  • I will try and see how it looks. I already bring the result :D

  • Really worked!

  • @Tiagoamaral I didn’t understand the purpose of your comment

  • Nothing with you does not @Dasilva ... is that I do not know how to get in direct contact with an administrator. I thought by marking him in the commentary he might see and answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.