Based on apple developer documentation:
A navigation controller object manages its child view controllers using an ordered array, known as the navigation stack. The first view controller in the array is the root view controller and represents the bottom of the stack. The last view controller in the array is the topmost item on the stack, and represents the view controller currently being displayed. You add and remove view controllers from the stack using segues or using the methods of this class.
for achieving the pop without animation you should do:
- access viewControllers property which is UINavigationController stack, but you can pop from every where in this array.
var viewControllers: [UIViewController]
The view controllers currently on the navigation stack.
example:
yourViewController.navigationController.viewControllers = [specificVC,self]
- It is better to create an extension and call it wherever you want:
Implement:
import UIKit
extension: UIViewController {
func setNext(to root: UIViewController? = nil) {
guard let navigation = self.navigationController,
let first = navigation.viewControllers.first else {return}
if let root = root {
navigation.viewControllers = [root,self]
}else{
navigation.viewControllers = [first,self]
}
}
}
Usage:
self.setNext(to: specificVC)