3

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

选项卡栏 - A(导航控制器的根 vc)-> Push VC -> B -> Present VC -> C

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

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

现在,当我 self.dismiss(animated: true, completion: nil)在视图控制器 C 中使用时,它会返回到根视图控制器,即 vc A。我希望它转到 VC B。

问题视频

4

1 回答 1

1

经过一番思考,我复制了您正在尝试做的事情,并发现问题不在于调用解雇。这与您首先调用该视图控制器的方式有关。稍微改变你的“B to C”代码。

代替:

让 vc = CViewController()

vc.modalPresentationStyle = .fullScreen

self.present(vc,动画:真,完成:无)

利用:

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

您必须在情节提要中指定视图控制器的标识符(情节提要 ID)

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

于 2020-01-08T06:05:44.090 回答