0

I am getting an error when I start typing text in a UITextfield:
unrecognized selector sent to instance

var inputTextField: UITextField!
let alertController = UIAlertController(title: "User Name", message: "Enter your new ideatrr name", preferredStyle: .Alert)

let nextAction: UIAlertAction = UIAlertAction(title: "Update", style: .Default) { action -> Void in
        if inputTextField!.text == "" {
            println("blank text")
        }
    }

nextAction.enabled = false

let cancel = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in
    alertController.addAction(nextAction)
    alertController.addAction(cancel)

    alertController.addTextFieldWithConfigurationHandler { (textField) -> Void in
        inputTextField = textField
        inputTextField.placeholder = "Enter your name"
        inputTextField.addTarget(self, action: "textFieldDidChange:", forControlEvents: UIControlEvents.EditingChanged)  
    }

    presentViewController(alertController, animated: true, completion: nil)

    func textFieldDidChange(inputTextField: UITextField!) {
        if inputTextField.text.isEmpty {
            nextAction.enabled = true
        } else {
            println("ddddd")
        }
    }
}
Marcus Rossel
  • 3,196
  • 1
  • 26
  • 41

1 Answers1

0

The function textFieldDidChange: needs to be an instance method of whatever class you're working in. If you move textFieldDidChange: into your class definition, you should be good to go.

rudd
  • 846
  • 7
  • 17