iphone - 单击输入按钮或搜索按钮时隐藏键盘

标签 iphone uisearchbar uibarbuttonitem uitoolbar

我已在工具栏按钮内的 UIBarButtonItem 内添加了 UISearchBar 按钮。

采用以下形式:

// search bar
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 260, 44)];
UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
[searchBar release];

[buttons addObject:searchBarButtonItem];

现在,当我单击 UISearchBar 键盘时出现问题。我想在单击输入或搜索按钮时隐藏键盘。我该怎么做?

最佳答案

实现 UISearchBarDelegate 中的方法:

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

关于iphone - 单击输入按钮或搜索按钮时隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7227128/

相关文章:

ios - 为什么要调整此 UISearchBar 的大小?

swift - 如何在 UISearchBar 中搜索结果?

ios - 以编程方式更改 iOS UIBarButtonItem

iphone - UISearchBar 在每次输入字母时调用 API,而不是在单击搜索按钮时调用 API

iphone - UISearchBar inputAccessoryView

ios - UIViewController 自定义后退导航按钮

iphone - UISegmentedControl 不检测 iOS5 中的段更改

iphone - 如何从pdf文件中的FileAttachment Annotation获取图像

ios - iPhone MKMapView - MKPolygon 问题

iphone - 在 iOS 的邮件编辑器中设置收件人字段的问题