gpt4 book ai didi

swift - 看起来返回键对我的方法不起作用

转载 作者:行者123 更新时间:2023-11-30 13:37:07 26 4
gpt4 key购买 nike

我正在 Swift 中开发一个程序,它实际上就像一个小型测试(如果您熟悉 MVC,该模型包含所有信息、问题、答案等)。但是,我无法获得我的程序的文本框响应 iOS 中虚拟键盘上的返回。难道我做错了什么?谢谢!

func textFieldShouldReturn(textField: UITextField) -> Bool {


model.recordAnswer(textField.text!)
numCorrect = model.numOfCorrectAnswers
numWrong = model.numOfIncorrectAnswers
txtViewQuestionStatus.text = "\(model.incorrectItems())\n"
model.theQuestion++
if model.hasMoreQuestions == true {
updateQuestionAndAnswer()
}
textField.resignFirstResponder() //hide keyboard
return true
}

最佳答案

请确保调用了上述函数。如果它没有被调用,那么您需要设置文本字段的委托(delegate)。您可以按如下方式执行此操作:

如果 txtViewQuestionStatus 这是您的 UITextField,请在您的 viewDidLoad() 方法中添加以下行:

txtViewQuestionStatus.delegate = self

如果上面的行有错误,显示未设置委托(delegate),则需要在类中添加 UITextFieldDelegate 。喜欢:

class ViewController : UIViewController  <UITextFieldDelegate>

关于swift - 看起来返回键对我的方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35955360/

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