通过POP UP操作按钮(UIAlertAction)查看控制器导航/转换



以下是我在swift(Xcode)中用于创建弹出窗口的代码行。

//create the alert
let alert=UIAlertController(title: "Better Luck Next Time", message: "Try Again Later", preferredStyle: UIAlertControllerStyle.Alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
// show the alert
self.presentViewController(alert,
                           animated: true,
                           completion: nil)

一旦用户按下弹出菜单中的OK按钮;我希望应用程序导航到另一个视图控制器。我知道我必须在UIAlertAction的处理程序部分放几行代码。但我不确定如何对这种转换进行编码。任何人都有任何简单有效的想法??。

let alertController = UIAlertController(title: "Default AlertController", message: "A standard alert", preferredStyle: .Alert)
            let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action:UIAlertAction!) in
                println("you have pressed the Cancel button");
            }
            alertController.addAction(cancelAction)
            let OKAction = UIAlertAction(title: "OK", style: .Default) { (action:UIAlertAction!) in
                println("you have pressed OK button");
                if let navController = self.navigationController
                {
                          navController.popViewControllerAnimated(true)
                }
            }
            alertController.addAction(OKAction)

            self.presentViewController(alertController, animated: true, completion:nil)

相关内容

最新更新