         alert.addTextFieldWithConfigurationHandler {
             (tf: UITextField) in
             tf.keyboardType = .NumberPad
+            tf.addTarget(self, action: #selector(AlertViewController.textChanged(_:)), forControlEvents: .EditingChanged)
         }
         
         alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (act: UIAlertAction) in

        }))
        
        alert.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
    }


        print("User tapped \(act.title)")
    }
    
    func textChanged(sender: UITextField) {
        // print("TextField changed: \(sender.text)")
        
        var resp : UIResponder = sender
        while !(resp is UIAlertController) {
            resp = resp.nextResponder()!
        }
        
        let alert = resp as! UIAlertController
        alert.actions[0].enabled = (sender.text != "")
    }
}
