我想在当前显示在堆栈上的视图控制器之前插入一个新的视图控制器。我尝试过这样的事情:
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 )
}
然而,当我弹出新视图控制器时没有显示。我怎么做到这一点?
答案 0 :(得分:2)
你这么说:
if var vcs: [UIViewController] = navigationController?.viewControllers {
vcs.insert(vc, at: vcs.count - 1)
但是,仅仅这个代码是毫无意义的。您已将视图控制器插入vcs
,是的;但navigationController.viewControllers
不受影响。然后vcs
被扔掉;它没用。
您需要添加以下行:
navigationController?.viewControllers = vcs
答案 1 :(得分:1)
你必须重新分配数组
if var vcs: [UIViewController] = navigationController?.viewControllers {
vcs.insert(vc, at: vcs.count - 1)
navigationController?.viewControllers = vcs
navigationController?.popViewController(animated: true )
}