键盘异步任务后并没有消除在迅速[复制]

问题描述 投票:1回答:1

这个问题已经在这里有一个答案:

我在做使用的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
}

我想键盘辞退一旦我们点击搜索按钮和异步任务也应该开始。

ios swift keyboard dismiss
1个回答
0
投票

你必须辞职的第一响应。

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讨论

© www.soinside.com 2019 - 2024. All rights reserved.