我的 ViewController 类实现了 UITextFieldDelegate。我没有自动完成诸如 textFieldShouldBeginEditing 之类的功能。这是 XCode 6 中的错误吗?这是我的类实现。
class ViewController: UIViewController, UITextFieldDelegate
最佳答案
class ViewController: UIViewController,UITextFieldDelegate //set delegate to class
@IBOutlet var txtValue: UITextField //create a textfile variable
override func viewDidLoad() {
super.viewDidLoad()
txtValue.delegate = self //set delegate to textfile
}
func textFieldDidBeginEditing(textField: UITextField!) { //delegate method
}
func textFieldShouldEndEditing(textField: UITextField!) -> Bool { //delegate method
return false
}
func textFieldShouldReturn(textField: UITextField!) -> Bool { //delegate method
textField.resignFirstResponder()
return true
}
关于ios - 使用 Swift 实现 UITextFieldDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24171857/