ios - 如何在导航堆栈中插入一个新的 View Controller 然后弹出它?

标签 ios swift uinavigationcontroller

我想在当前出现在堆栈上的 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/

相关文章:

ios - 点击 UITableViewCell 时如何正确显示 UINavigationController?

ios - 什么时候获取 apple-app-site-association 文件?

ios - 如何关闭 ios 中的 Popover View

ios - TestFlight 是否支持 ios7 及更早版本?

ios - 在我按下开始游戏后为我的 NSTimer 添加延迟

ios - 单个 VIPER 模块中的多个 View Controller

swift - 未找到 <TypeName> 类型的 ObservableObject。 View.environmentObject(_ :) for <TypeName> may be missing as an ancestor of this view

ios - 如果通过 segue 从另一个选项卡进入,如何从 Controller 中删除 TabBar?

c++ - 检测文本数字太大而无法在 swift 中转换为 Int

swift - navigationController 在 swift 中为 nil