按下文本框返回按钮后不退出键盘

时间:2019-04-15 23:55:21

标签: ios swift textfield

我是Swift和Xcode的新手,仍然遇到一些问题。当我触摸文本字段时,键盘会弹出,这是我想要的,但是当我尝试退出键盘时会出现问题。返回按钮不起作用,我已经尝试了如代码所示的resignFirstResponder()方法。我在做什么错了?

class QuestionSubmit: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var TextBox: UITextField!
    @IBOutlet weak var ScrollView: UIScrollView!

    @IBOutlet weak var thankslabel: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()

    }

    @IBAction func SubmitButton(_ sender: Any) {
        TextBox.text = ""
        thankslabel.text = "Thank you for your submission!"
    }

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()

        return true
    }
}

0 个答案:

没有答案