您所需要做的就是将导航控制器的viewControllers
属性设置为一个包含两个元素的数组--根视图控制器(VC1)和新的VC4.
if let navigationController {
let vc4 = ... // initialise VC4 appropriately
// make the array
let newStack = [navigationController.viewControllers[0], vc4]
// this sets viewControllers, with a "push" transition
navigationController.setViewControllers(newStack, animated: true)
}
如果您想要"POP"转换,首先删除viewControllers
中除第一个和最后一个元素之外的所有元素,然后在其余两个VC之间插入VC4.然后你可以从popViewController(animated: true)
go VC4.
if let navigationController {
let vc4 = ...
navigationController.viewControllers.removeSubrange(1..<navigationController.viewControllers.count - 1)
navigationController.viewControllers.insert(vc4, at: 1)
navigationController.popViewController(animated: true)
}