Reputation: 6471
I am using following code for adding UISearchBar
in iOS7 and UISearchBar
appearance is fine.But problem is when press cancel button on UISearchBar
then UIKeyboard
appeared.Why its happen?Please help me.
CGRect searchFrame = CGRectMake(self.view.bounds.origin.x, 64, self.view.bounds.size.width, 44.0f);
self.mySearchBar = [[UISearchBar alloc]initWithFrame:searchFrame];
self.mySearchBar.delegate = self;
self.mySearchBar.searchBarStyle = UISearchBarStyleDefault;
self.mySearchBar.placeholder = @"search items;
self.mySearchBar.showsCancelButton = YES;
[self.view addSubview:self.mySearchBar];
Upvotes: 0
Views: 184
Reputation: 5602
I got your issue now.
When there is not text entered at that time cancel button will be disabled. So if you try to press it than it will consider SearchBar text area & Keyboard will appear.
While you enter the text than Cancel button will be active & than it will work.
Hope you'll get the solution from this.
Upvotes: 0
Reputation: 23624
Implement the searchBarCancelButtonClicked:
UISearchBarDelegate
method. If you want the keyboard to go away you would do something like:
- (void) searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
Upvotes: 1