我正在使用以下代码在 iOS7 中添加 UISearchBar
并且 UISearchBar
外观很好。但是问题是当按下 UISearchBar
上的取消按钮时UIKeyboard
出现了。为什么会这样?请帮助我。
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];
最佳答案
实现 searchBarCancelButtonClicked:
UISearchBarDelegate
方法。如果您希望键盘消失,您可以执行以下操作:
- (void) searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
}
关于ios - 为什么按下 UISearchbar 上的取消按钮时会出现 UIKeyboard?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22680778/