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?
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];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With