Kelvin Lau
Kelvin Lau

Reputation: 6781

Programatically detecting events from UI elements

I've looking at some arcane construct namely this:

cell.phoneNumberField.removeEventHandlers(forControlEvents: .EditingChanged)
cell.phoneNumberField.addEventHandler(forControlEvents: .EditingChanged) { field in
    self.formValues[formField.id] = (field as! //...)
}

In Swift 2, those 2 method calls have either vanished into existence. I'm having trouble finding suitable replacements for the calls.

Upvotes: 0

Views: 33

Answers (1)

nRewik
nRewik

Reputation: 9148

You can use - addTarget:action:forControlEvents:

textField.addTarget(nil, action: "textChanged:", forControlEvents: .EditingChanged)

and then handle the event with textChanged function

func textChanged(sender: UITextField){
    print(sender.text)
}

Upvotes: 2

Related Questions