0

I have a textfield which opens up a keyboard, but I need to somehow get the letter that the user types after every tap of the keyboard, like a live update.

I think the best way of doing this is using some kind of function to constantly check the text of the textfield, but I'm not sure.

Any help is appreciated. Thanks!

zach
  • 195
  • 1
  • 1
  • 9

2 Answers2

0

First set delegate of the textfield, then use the following code

func textField(textField: UITextField,
    shouldChangeCharactersInRange range: NSRange,
    replacementString string: String) -> Bool {

let newString = (textField.text as NSString).stringByReplacingCharactersInRange(range, withString: string)
}
Fawad Masud
  • 12,219
  • 3
  • 25
  • 34
0

You could use a target on your textField with the control event EditingChanged instead of the delegate method. myTextField.addTarget(self, action: "didChangeText:", forControlEvents: .EditingChanged) Then use the targeted method to run your checks.

  func didChangeText(textField:UITextField)
 { 
if textField.text == "apple" 
{ 
 checkImageView1.hidden = false 
}
 else 
  { 
    checkImageView1.hidden = true 
  }
 }
Piyush
  • 1,534
  • 12
  • 32