【发布时间】:2015-02-10 16:45:42
【问题描述】:
我对 Swift 开发很陌生,我尝试参考 Swift UIAlertController API,但在单击 UIAlertController 上的按钮后无法弄清楚如何导航到另一个 UIViewController。
我将不胜感激任何指针、帮助或解决此问题的方法。我的代码 sn-p 如下 -
@IBAction func showAlert() {
let alertController = UIAlertController(title: "Disclaimer", message: "Disclaimer Text Here", preferredStyle: .Alert)
let declineAction = UIAlertAction(title: "Decline", style: .Cancel, handler: nil)
alertController.addAction(declineAction)
let acceptAction = UIAlertAction(title: "Accept", style: .Default) { (_) -> Void in
let secondVC = ViewController(nibName: "ViewController", bundle: nil)
let navController = UINavigationController(rootViewController: secondVC)
self.presentViewController(navController, animated: true, completion: nil)
}
alertController.addAction(acceptAction)
presentViewController(alertController, animated: true, completion: nil)
}
我在这里尝试做的是单击按钮时显示免责声明 AlertController。如果选择了 "Decline" 按钮,则会执行取消操作,如果选择了 "Accept",应用程序应该导航到导航控制器,然后我可以导航到其他视图控制器使用应用程序中的菜单。
之前我使用故事板将一个按钮链接到 NavigationController 以遍历我想要的 ViewController。现在我想以编程方式对 AlertController "Accept" 按钮执行相同的操作。
提前谢谢你。
【问题讨论】:
标签: ios swift uiviewcontroller xcode6 uialertcontroller