gpt4 book ai didi

ios - 警报完成未完全正常工作

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

我有一个警报,在警报显示后,我想展示一个不同的取景器。 doSomething() 函数被触发,“TEST”被打印出来,但是新的取景器没有出现。我错过了什么?

提醒

let alert = UIAlertController(title: "Sorry", message: "Booked out.",
preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style:
UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: self.doSomething)

内容函数 doSomething()

print("TEST")
let details = storyboard?.instantiateViewController(withIdentifier: "ViewLimo2")
details?.transitioningDelegate = slideAnimatorRight
present(details!, animated: true, completion: nil)

最佳答案

View Controller 上的完成 block 不会在 View Controller 被关闭时触发。它在 View Controller 完成呈现时触发(例如,它已完成 viewDidAppear)。

老实说,我预计这会崩溃,因为您正在尝试在警报仍在呈现时呈现。

在任何情况下,您都需要等到 UIAlertController 被关闭,然后再尝试呈现下一个 View Controller。

您可以在 OK 操作的处理程序中执行此操作:

    let alert = UIAlertController(title: "Sorry", message: "Booked out.",
preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "OK", style:
UIAlertActionStyle.default, handler: doSomething))
self.present(alert, animated: true, completion: nil)

...

func doSomething(action:UIAlertAction) {
/// present the next VC here
}

关于ios - 警报完成未完全正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49139880/

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