Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing UITextFieldDelegate with Swift

Tags:

I have my ViewController class which implements UITextFieldDelegate. I have no auto complete for the funcs such as textFieldShouldBeginEditing. Is this a bug in XCode 6? Here's my class implementation.

class ViewController: UIViewController, UITextFieldDelegate 
like image 331
Beanwah Avatar asked Jun 11 '14 20:06

Beanwah


2 Answers

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 } 
like image 66
jayesh kavathiya Avatar answered Oct 31 '22 11:10

jayesh kavathiya


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;     } 
like image 36
Kiran K Avatar answered Oct 31 '22 11:10

Kiran K