gpt4 book ai didi

ios - 父 View Controller 未被解散

转载 作者:行者123 更新时间:2023-11-28 12:38:40 24 4
gpt4 key购买 nike

presentViewController 函数有问题。

我有一个登录菜单 (A) 和一个显示登录表单的按钮 (B)。成功登录后,我使用 self.presentViewController (C) 呈现第三个 View 。

登录菜单(A)-> 登录表单(B)-> 内容(C)

成功了,我可以显示第三个 View (C),但登录菜单 (A) 始终可见(我可以在 UI Debug模式中看到它)。

那么,如何关闭A ViewController呢?

最佳答案

presentViewController,以模态方式呈现 View Controller 。换句话说,覆盖当前 View Controller 的内容,当前 View Controller 不会被释放。

为您的示例使用以下代码:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: <Identifier as in Storyboard of C>)
(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = vc

如果你想包含一个过渡,你可以用下面的内容替换最后一行:

UIView.transition(from: currentRootViewController!.view, to: vc.view, duration: 0.8, options: .transitionCrossDissolve, completion: { (_) in
(UIApplication.shared.delegate as! AppDelegate).window?.rootViewController = vc
})

关于ios - 父 View Controller 未被解散,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40108967/

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