UIAlertViewController显示我的所有文字,但点击后不会切换到另一个视图。这是代码:
let alertController = UIAlertController(title: "Risposta Esatta", message:"", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Avanti", style:UIAlertActionStyle.Default,handler: {(UIAlertAction) in
let secondViewController:SecondViewController = SecondViewController()
self.presentViewController(secondViewController, animated: true, completion: nil)
}))
答案 0 :(得分:0)
这对我有用:
@IBAction func choiceBtn(sender: UIButton) {
let alertController = UIAlertController(title: "Hello!", message: "This is Alert sample.", preferredStyle: .Alert)
let otherAction = UIAlertAction(title: "OK", style: .Default) {
action in println("pushed OK!")
}
let cancelAction = UIAlertAction(title: "CANCEL", style: .Cancel) {
action in self.performSegueWithIdentifier("VC2", sender: self)
}
alertController.addAction(otherAction)
alertController.addAction(cancelAction)
presentViewController(alertController, animated: true, completion: nil)
}
我创建了一个模式,从VC1到VC2呈现了segue,并且还命名了标识符VC2。这段代码我改编自GitHub UIAlertController示例:
https://github.com/eversense/Swift-UIAlertController-Example
没有segue到另一个ViewController,所以我添加了它来向你展示。