Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide keyboard on search button click of search bar created by code

I have created a search bar using the code below:

 UISearchBar *Search = [[UISearchBar alloc]initWithFrame:CGRectMake(150, 0,170 , 50)];
[SearchView addSubview:Search];

But when I clicked on the search button the keyboard is not hidden. I have used many methods, like searchBarTextDidEndEditing and searchBarSearchButtonClicked. Maybe the reason is that my search bar is not attached. I have also used UISearchBarDelegate delegate in my .h class and in .m unload method:

Search.delegate = Self;

Can anyone suggest me how to attach my search bar created by code to my View Controller so it should work?

like image 375
Guri Avatar asked Jan 08 '14 08:01

Guri


1 Answers

First you need to set delegate of your searchBar and then You should use following delegate method of UISearchBar such like,

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];

}
like image 105
iPatel Avatar answered Oct 13 '22 20:10

iPatel