UIAlertController 按钮单击导航到 NavigationController 的第一个 ViewController

UIAlertController button click navigates to a NavigationController's first ViewController

我是 swift 和 iOS 编程的新手。我有 StartViewController,它有一个按钮,当单击带有两个按钮的 UIAlertController - Decline & 接受。单击 Accept 时,我想导航到 MyNavigationController 的 - ViewController . MyNavigationController 有四个 ViewController,我使用滑动菜单导航到它们。

我附上了我的故事板的示例代码和屏幕截图以供参考。

 @IBAction func showAlert() {

    let alertController = UIAlertController(title: "Disclaimer", message: "Before using this teaching resource, you confirm that you agree:\n1. To obey the law regarding data protection and patient confidentiality.\n2. To us this app professionally and appropriately in clinical settings.\n3. This is for your personal use and you may not modify, distribute, publish, transfer any information obtained from this teaching resource without the developers' permission.\n4. In no event shall the developer be liable to you for any loss arising from your use of this resource.", preferredStyle: .Alert)


    let declineAction = UIAlertAction(title: "Decline", style: .Cancel, handler: nil)
    alertController.addAction(declineAction)

    let acceptAction = UIAlertAction(title: "Accept", style: .Default) { (_) -> Void in

             //I think the code to navigate should go here, help please.

    }

    alertController.addAction(acceptAction)

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

}

故事板截图 -

在上面的屏幕截图中,登录 按钮打开一个 UIAlertController alertController。此 AlertController 上的 Accept 按钮应导航到 MyNavigationController 上的 ViewController

这个 MyNavigationController 有另外三个 ViewController 使用滑动菜单导航。

提前致谢。

您需要在当前视图控制器和目标视图控制器之间创建一个转场,并确保转场 ID 与您的 performSegueWithIdentifier 调用

中的 ID 匹配
@IBAction func showAlert() {

    let alertController = UIAlertController(title: "Disclaimer", message: "Before using this teaching resource, you confirm that you agree:\n1. To obey the law regarding data protection and patient confidentiality.\n2. To us this app professionally and appropriately in clinical settings.\n3. This is for your personal use and you may not modify, distribute, publish, transfer any information obtained from this teaching resource without the developers' permission.\n4. In no event shall the developer be liable to you for any loss arising from your use of this resource.", preferredStyle: .Alert)

    let declineAction = UIAlertAction(title: "Decline", style: .Cancel, handler: nil)
    let acceptAction = UIAlertAction(title: "Accept", style: .Default) { (_) -> Void in    

        self.performSegueWithIdentifier("SomeSegue", sender: self) // Replace SomeSegue with your segue identifier
    }

    alertController.addAction(declineAction)
    alertController.addAction(acceptAction)

    presentViewController(alertController, animated: true, completion: nil)
}