【发布时间】:2015-08-23 10:12:34
【问题描述】:
我正在尝试重现可以在 iphone 上的联系人应用程序中看到的功能。我有一个 UISearchBar 在单击搜索按钮时会关闭键盘。但是,这会停用取消按钮,并且需要 2 次触摸才能激活。在联系人应用程序上,当单击搜索按钮并关闭键盘时,它不会被停用。
所以我要问的是如何在不停用 uiSearchBar 上的取消按钮的情况下关闭键盘?
我试过了
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
//Some other code
//I have Tried
//Attempt 1
self.searchBar.endEditing(true)
//Attempt 2
self.searchBar.resignFirstResponder()
//Attempt 3
var textFieldInsideSearchBar = searchBar.valueForKey("searchField") as? UITextField
textFieldInsideSearchBar.endEditing(true)
}
【问题讨论】:
标签: ios swift uisearchbar uikeyboard