ios - 为什么按下 UISearchbar 上的取消按钮时会出现 UIKeyboard?

标签 ios iphone objective-c xcode5 uisearchbar

我正在使用以下代码在 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/

相关文章:

iOS谷歌VR SDK : Unable to preview Video

iphone - 如何判断两个物体是否相交?

iphone - CoreData 应用程序目录在 iOS3 上崩溃

ios - 发送到不可变对象(immutable对象)的变异方法,只发生在物理设备上

ios - UITableViewCell 类中的 PerfomSegue

ios - 从 data core ios 获取数据

iphone - 返回到 iPhone 上使用 Core Data 的基于钻取导航的应用程序中的列表

iphone - 关于 iPhone 上的 ivars 和 @property 的问题

iphone - 如何从 Objective-C 代码中删除一次性使用的类变量?

iphone - [NSCFString objectAtIndex :]: unrecognized selector sent to instance when using nsmutabledictionery