基本上我有一个 uialertaction ,需要在按下时显示另一个 View Controller 。起初我这样做了,但现在即使我没有收到错误代码,应该打开的 View Controller 也只是一个黑色页面。
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。
您可以像这样向 AlertController 添加操作,而不是 dispatch_after ;
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 类可能有问题。
关于ios - 链接 UIAlertAction 打开另一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33367967/