这个问题已经在这里有一个答案:
我在做使用的UITextField和我点击搜索按钮,它应该开始异步任务FO调用Web API,并消除键盘一个搜索任务。但键盘依然存在。下面是代码
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
attemptPost { (success) in
DispatchQueue.main.async {
spinner.stopAnimation(self)
btnOk.isEnabled = true
btnCancel.isEnabled = true
}
// after this keyboard should dismiss but does not do so
return true
}
func attemptPost(_ completion:@escaping (Bool)->()) {
// some code
}
我想键盘辞退一旦我们点击搜索按钮和异步任务也应该开始。
你必须辞职的第一响应。
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
attemptPost { (success) in
DispatchQueue.main.async {
spinner.stopAnimation(self)
btnOk.isEnabled = true
btnCancel.isEnabled = true
}
textField.resignFirstResponder()
return true
}
看到https://developer.apple.com/documentation/uikit/uitextfielddelegate/1619603-textfieldshouldreturn讨论