我想在当前出现在堆栈上的 View Controller 之前插入一个新的 View Controller 。我试过这样的事情:
let vc: ECAssessmentVC = ECAssessmentVC.createViewController()
vc.mode = .assessmentResults
vc.quizzes = quizzes
if var vcs: [UIViewController] = navigationController?.viewControllers {
vcs.insert(vc, at: vcs.count - 1)
navigationController?.popViewController(animated: true )
}
但是,当我弹出时,新的 View Controller 没有显示。我将如何实现这一点?
最佳答案
你是这样说的:
if var vcs: [UIViewController] = navigationController?.viewControllers {
vcs.insert(vc, at: vcs.count - 1)
但仅凭该代码是毫无意义的。你已经在 vcs
中插入了一个 View Controller ,是的;但 navigationController.viewControllers
不受影响。然后 vcs
被丢弃;这是没用的。
你需要添加这一行:
navigationController?.viewControllers = vcs
关于ios - 如何在导航堆栈中插入一个新的 View Controller 然后弹出它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49842096/