Wednesday, 20 May 2015

swift uitextfielddelegate textchanged





  override func viewDidLoad() {
    super.viewDidLoad()

    userNameTextField.delegate = self
    userNameTextField.addTarget(self, action: "userNameDidChange:", forControlEvents: UIControlEvents.EditingChanged)

  }

  func userNameDidChange(textField: UITextField) {
       println("userNameDidChange")
  }

This function will be called every simple time when use typing. e.g. if they type in "123", you will get 3 calls.



-------
  func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool{
    println("shouldChangeCharactersInRange")
    return true
  }
  This function works as above one, it will get 3 calls if users input "123"


  func textFieldDidEndEditing(textField: UITextField){
    println("textFieldDidEndEditing")

  }
   This function will get call only the textField lost focus.

----


  @IBAction func editchanged(sender: AnyObject) {
    println("editchanged")

  }
  it will get 3 calls if users input "123"
  
  @IBAction func editingDidEnd(sender: AnyObject) {
    println("editingDidEnd")
  }

   This function will get call only the textField lost focus.
  
  @IBAction func valueChange(sender: AnyObject) {
    println("valueChange")
  }
  never get called.
  





No comments:

Post a comment