我有一个实现UITextFieldDelegate的ViewController类。我没有像textFieldShouldBeginEditing这样的函数自动补全。这是XCode 6中的错误吗?这是我的类实现。
class ViewController: UIViewController, UITextFieldDelegate
发布于 2014-06-12 04:23:32
Xcode 6 (Beta 1)目前不支持未实现的协议方法/属性的自动完成(用于Swift)。
您最好的选择是对尚未完全实现的协议执行<CMD> - click
,以查看您遗漏了什么。
发布于 2014-07-07 14:18:48
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
}
发布于 2016-12-02 17:59:32
Swift 3.0.1
// UITextField Delegates
func textFieldDidBeginEditing(_ textField: UITextField) {
}
func textFieldDidEndEditing(_ textField: UITextField) {
}
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
return true;
}
func textFieldShouldClear(_ textField: UITextField) -> Bool {
return true;
}
func textFieldShouldEndEditing(_ textField: UITextField) -> Bool {
return true;
}
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
return true;
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder();
return true;
}
https://stackoverflow.com/questions/24171857
复制相似问题