gpt4 book ai didi

ios - 在第一个关闭后显示第二个模态视图 Controller

转载 作者:行者123 更新时间:2023-11-28 09:48:51 26 4
gpt4 key购买 nike

我有两个模态打开的 View Controller 。当第一个 VC 关闭时,第二个应该打开。但是当我关闭第一个时,第二个根本不显示。有什么问题吗?

我的代码是:

self.dismiss(animated: true) {
let flowVC = LanguageFlowViewController()
self.present(flowVC, animated: true)
}

最佳答案

您需要从您展示第一个 View Controller 的地方引用 View Controller 。

例如,您的 View Controller 名称为 X,从那里您的第一个 View Controller A 出现了。所以你需要引用X来呈现B,因为A在内存中不可用。

因此,当您尝试使用 self 呈现第二个 View Controller 时,它不会执行任何操作。

因此,对于解决方案,将 X View Controller 的引用分配给 A。在 A 类中,声明:

var refX: X?

当从 X 呈现 A 时,将 self 设置为 refX。喜欢:

var aVC = A() // This is temp, you need to instantiate your view controller here.
aVC.refX = self
self.present(aVC, animated: true, completion: nil)

现在,在 View Controller A 内部,当关闭时:

var bVC = B() // This is temp, you need to instantiate your view controller here.
self.dismiss(animated: true) {
if self.refX != nil {
self.refX?.present(bVC, animated: true, completion: nil)
}
}

希望对您有所帮助。

关于ios - 在第一个关闭后显示第二个模态视图 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53829149/

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