私のUITextFieldsの入力が1050未満のときにアラートが表示されるようなコードを記述しました。入力がそれを満たすときに表示されますが、即座に再表示されます。UIAlertControllerは終了後も再表示されます
以下はviewDidLoad
関数のコードです:
override func viewDidLoad(){
super.viewDidLoad()
alert = UIAlertController(title: "Error", message: "Please enter an exit width value greater than 1050", preferredStyle: UIAlertControllerStyle.Alert)
let okay = UIAlertAction(title: "OK", style: UIAlertActionStyle.Destructive, handler: valueCalc)
alert.addAction(okay)
}
は、それから私は(ボタンをタップしたときに呼び出される)私のvalueCalc
機能を持っている:
@IBAction func valueCalc(sender: AnyObject){
if(Int(mmText.text!)! < 1050){ //mmText is an UITextField
self.presentViewController(alert, animated: true, completion: nil)
}
}