Link 打开另一个 UIAlertAction ViewController

Link UIAlertAction to open another ViewController

基本上我有一个 uialertaction 需要在按下时显示另一个 viewcontroller。起初我做到了,但现在即使我没有收到错误代码,应该打开的 viewcontroller 也只是一个黑页。

            if((user) != nil) {

                let alert = UIAlertController(title: "Succesfull", message: "Logged In", preferredStyle: UIAlertControllerStyle.Alert)

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

                        let delay = 2.0 * Double(NSEC_PER_SEC)

                            let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay))
                            dispatch_after(time, dispatch_get_main_queue(), {

                            alert.dismissViewControllerAnimated(true, completion: { () -> Void in

                                let logInViewController = BoardViewController()

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

实际上几天前我 运行 遇到过这样的问题,但我无法正确理解答案。所以谁能解释一下为什么会发生并且没有给出任何错误

您的 AlertController 没有任何操作。您刚刚在显示 AlertController 2 秒后显示 logInViewController

代替 dispatch_after ,您可以像这样向 AlertController 添加操作;

if(user != nil) {
      let alert = UIAlertController(title: "Succesful", message: "Logged In", preferredStyle: UIAlertControllerStyle.Alert)
      let action = UIAlertAction(title: "OK", style: .Cancel, handler: { // Also action dismisses AlertController when pressed.
            action in

              let logInViewController = BoardViewController()
              self.presentViewController(logInViewController, animated: true, completion: nil) // When press "OK" button, present logInViewController

                }
        )
      alert.addAction(callAction)// add action to alert
      self.presentViewController(alert, animated: true, completion: nil)// show AlertController
}

如果您从 BoardViewController 得到空白页,那么您可能在 BoardViewController class.

中有问题