我已经写代码,出现报警时,在我的UITextFields的一个输入小于1050中输入满足这一点,但我后按"确定"它会立即重新出现时出现成功.
下面是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)
}
Run Code Online (Sandbox Code Playgroud)
然后我有我的valueCalc功能(当点击按钮时调用):
@IBAction func valueCalc(sender: AnyObject){
if(Int(mmText.text!)! < 1050){ //mmText is an UITextField
self.presentViewController(alert, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)