gpt4 book ai didi

ios - 链接 UIAlertAction 以打开另一个 ViewController

转载 作者:搜寻专家 更新时间:2023-11-01 07:29:47 24 4
gpt4 key购买 nike

基本上我有一个 uialertaction 需要在按下时显示另一个 viewcontroller。起初我这样做了,但现在即使我没有收到错误代码,应该打开的 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

代替 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 类可能有问题。

关于ios - 链接 UIAlertAction 以打开另一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33367967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com