ios – Clear/Take away a number of ViewController in NavigationController


All it’s essential do is to set the navigation controller’s viewControllers property to an array of two components – the foundation view controller (VC1), and the brand new VC4.

if let navigationController {
    let vc4 = ... // initialise VC4 appropriately
    // make the array
    let newStack = [navigationController.viewControllers[0], vc4]
    // this units viewControllers, with a "push" transition
    navigationController.setViewControllers(newStack, animated: true)
}

If you need a “pop” transition as a substitute, first take away all the weather in viewControllers besides the primary and the final, then insert VC4 in between the remaining 2 VCs. Then you possibly can popViewController(animated: true) to go to VC4.

if let navigationController {
    let vc4 = ... 
    navigationController.viewControllers.removeSubrange(1..<navigationController.viewControllers.depend - 1)
    navigationController.viewControllers.insert(vc4, at: 1)
    navigationController.popViewController(animated: true)
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles