Implementing UITextFieldDelegate with Swift

前端 未结 12 1237
后悔当初
后悔当初 2020-12-08 08:11

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?

12条回答
  •  [愿得一人]
    2020-12-08 08:52

    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
    }
    

提交回复
热议问题