Ramanuj Singh
Ramanuj Singh

Reputation: 115

Not able to Hide Keyboard on search button click for Iphone application

Hi I am new to xcode development I am creating a simple application. In that I have table view Controller with on Search bar control. onClick of Search bar Key board comes up I am not able to hide the key board. I tried to Hide it by

(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{       

[self resignFirstResponder];    
[self.searchbar setShowsCancelButton: NO animated: YES]; 

}

but It is not working.

Upvotes: 0

Views: 773

Answers (3)

Dhiraj Umale
Dhiraj Umale

Reputation: 92

I hope this will help you

if([text length] == 0) {
    [searchBar performSelector: @selector(resignFirstResponder)
                       withObject: nil
                       afterDelay: 0.1];
}

where text is searchbar text

Best of luck

Upvotes: 0

Ege Akpinar
Ege Akpinar

Reputation: 3286

To hide keyboard, you should lose focus on the text input, not the class instance itself (self)

In your case, you should do

[searchBar resignFirstResponder]

Upvotes: 1

esh
esh

Reputation: 2872

Try

[self.view endEditing:YES];

In your button's action.

Upvotes: 0

Related Questions