因此UIAlertController正确地在屏幕上显示警报,但是在xCode模拟器中按下确定没有任何操作,它也不会保留警报。 alert view image
func displayAlertMessage(userMessage:String) {
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil);
myAlert.addAction(okAction);
self.presentViewController(myAlert, animated: true, completion: nil);
}
答案 0 :(得分:1)
将UIAlertActionStyle.Default更改为UIAlertActionStyle.Cancel
func displayAlertMessage(userMessage:String) {
let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.Alert);
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Cancel, handler: nil);
myAlert.addAction(okAction);
self.presentViewController(myAlert, animated: true, completion: nil);
}
如果你想做好事
let okAction = UIAlertAction(title: "OK", style: .Default) { (action) in
//do whatever you want to do here
// for e.g dismiss view controller or segue your view controller etc.
}