当我开始在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")
}
}
}
答案 0 :(得分:0)
函数textFieldDidChange:
需要是您正在使用的任何类的实例方法。如果将textFieldDidChange:
移动到类定义中,您应该很高兴。