gpt4 book ai didi

ios - Xcode 7 键盘控制功能错误

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

我试图创建一个功能,以便通过单击键盘外部或键盘内的回车键来收起键盘,但不幸的是,它仅在我单击键盘外部时才起作用,按键盘不起作用键盘上的返回键。

import UIKit

class ViewController: UIViewController,UITextFieldDelegate {

@IBOutlet var numberEnter: UITextField!


@IBAction func findButton(sender: AnyObject) {

resultLabel.text = numberEnter.text
}


@IBOutlet var resultLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

self.view.endEditing(true)
}

func textFieldShouldReturn(textField:UITextField) -> Bool{

textField.resignFirstResponder()

return true

}

}

最佳答案

如果您尚未为文本字段设置委托(delegate),则需要执行此操作。您可以在 Interface Builder 或代码中设置委托(delegate)。请参阅此 StackOverflow 答案作为示例:Text Field Should Return, is this correct for ios7?

关于ios - Xcode 7 键盘控制功能错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33376987/

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