I have found many ways to pop back 2 UIViewControllers
in UINavigationController
using Objective-C, however when I try and switch that over to Swift it
I did a helper to make it easy:
import Foundation
import UIKit
class NavigationHelper {
static func back(number: Int, from viewControlller : UIViewController) {
let viewsBack = number + 1
let viewControllers: [UIViewController] = viewControlller.navigationController!.viewControllers as [UIViewController]
viewControlller.navigationController!.popToViewController(viewControllers[viewControllers.count - viewsBack], animated: true)
}
static func back(number: Int, from viewControlller: UITableViewController) {
let viewsBack = number + 1
let viewControllers: [UIViewController] = viewControlller.navigationController!.viewControllers as [UIViewController]
viewControlller.navigationController!.popToViewController(viewControllers[viewControllers.count - viewsBack], animated: true)
}
}
For example, in your ViewController
you can use NavigationHelper.back(number: 1, from: self)