gpt4 book ai didi

ios - 仅关闭呈现的 View Controller 而不是整个导航堆栈 Swift

转载 作者:行者123 更新时间:2023-12-01 16:21:11 25 4
gpt4 key购买 nike

我有一个标签栏 Controller 。其中第一个选项卡是导航 Controller 。让我们称之为 Controller A。然后我将另一个 View Controller 推到它上面。让我们称之为 Controller B。之后,我从 View Controller B 中呈现 View Controller C。现在我只想关闭 View Controller B。

Tab Bar - A(Navigation Controller's root vc) -> Push VC -> B -> Present VC -> C

A 到 B 正在使用 self.navigationController.pushViewController(animated: true, completion: nil)

B到C是这样的
让 vc = CViewController()
vc.modalPresentationStyle = .fullScreen
self.present(vc,animated: true,completion: nil)

现在当我使用self.dismiss(animated: true, completion: nil) 在 View Controller C 中。它返回到 Root View Controller ,即 vc A。我希望它转到 VC B。

Video of issue

最佳答案

经过一番思考,我复制了您尝试执行的操作,并发现问题不在于调用 dismiss。首先是您调用该 View Controller 的方式。稍微更改您的“B 到 C”代码。

代替:

let vc = CViewController()

vc.modalPresentationStyle = .fullScreen

self.present(vc,animated: true,completion: nil)

使用:

let sb : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(identifier: "C")
vc.modalPresentationStyle = .fullScreen
self.present(vc, animated: true, completion: nil)

您必须在 Storyboard 中指定 View Controller 的标识符( Storyboard ID)

现在当你调用 self.dismiss() 时,它应该只关闭 C。我已经在我的计算机上使用 Xcode 11.1 对此进行了测试。

关于ios - 仅关闭呈现的 View Controller 而不是整个导航堆栈 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59626336/

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