使用UISearchBar取消键盘,而不辞职第一个响应者 [英] Dismissing the keyboard with UISearchBar, without resigning first responder
问题描述
嘿,我正在iPhone上一个基于导航的应用程序上工作,类似于联系人应用程序。当您在搜索栏中输入内容并在表格(在联系人应用程序中)上滚动时,键盘会消失。我不认为它辞职第一响应,虽然,因为当我尝试,并在 - (void)scrollViewDidScroll:(UIScrollView *)scrollView,它禁用取消按钮,这不会发生在联系人应用程序。
Hey, I was working on a navigation-based app on iPhone similar to the contacts app. When you input something in the search bar, and scroll in the table (in the contacts app), the keyboard goes away. I don't think it resigns first responder though, because when I try and do that in -(void)scrollViewDidScroll:(UIScrollView *)scrollView, it disables the cancel button, which does not happen in the contacts app. Basically my question is how do I dismiss the keyboard without disabling the cancel button, like in the contacts app?
感谢
推荐答案
好吧,刚刚碰到这个老问题。
当您开始滚动时,您可以启用取消按钮,如下所示:
Well, just ran into this very old question. You can enable the 'cancel' button when you start to scroll as follows:
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
searchBar.resignFirstResponder()
let searchCancelButton = searchBar.valueForKey("cancelButton") as! UIButton
searchCancelButton.enabled = true // <-- THIS line is the trick
}
这篇关于使用UISearchBar取消键盘,而不辞职第一个响应者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!