<分区>
我正在使用 UItextField 执行搜索任务,我点击搜索按钮,它应该开始调用 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
}
我希望键盘在我们点击搜索按钮后关闭,异步任务也应该开始。