gpt4 book ai didi

ios - 我的键盘不会切换 : neither endEditing nor resignFirstResponder works

转载 作者:行者123 更新时间:2023-11-28 11:30:24 24 4
gpt4 key购买 nike

我正在使用文本字段,文本字段所在的 View 是由UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "nickNameInput") 作为!弹出 View Controller

这是一个 PopupViewController。

问题是当我打电话textField.resignFirstResponder()self.view.endEditing(true) ,它们都不起作用...

我很难过。有人可以帮帮我吗?

    import UIKit

class PopupViewController: UIViewController, UITextFieldDelegate{
@IBOutlet weak var editingEndBtn: UIButton!
@IBOutlet weak var textField: UITextField!
var inputString = ""

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
let blurEffect = UIBlurEffect(style: .extraLight)
let blurView = UIVisualEffectView(effect: blurEffect)
view.insertSubview(blurView, at: 0)

textField.delegate = self
editingEndBtn.isEnabled = false
}



func textFieldDidBeginEditing(_ textField: UITextField) { //delegate method
}

func textFieldShouldEndEditing(_ textField: UITextField) -> Bool { //delegate method
inputString = textField.text!
//print(inputString)
if (inputString != ""){
editingEndBtn.isEnabled = true
}

textField.resignFirstResponder()
self.view.endEditing(true)
return false
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool { //delegate method
textField.resignFirstResponder()
print("return is pushed")
toggleKeyboard()
return true
}


}

最佳答案

问题就在这里

func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {   
return false // this prevents it
}

你需要移除这个方法或者根据文本逻辑处理它而不像返回false一样

func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
inputString = textField.text!
return inputString != ""
}

关于ios - 我的键盘不会切换 : neither endEditing nor resignFirstResponder works,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56949369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com