侧滑返回至指定控制器(swift)

//侧滑返回至TargetViewController, 移除中间VC

    var tmp = NSMutableArray(array: self.navigationController!.viewControllers) as! [UIViewController]
    var minIndex: Int = 0
    for (index, vc) in tmp.enumerated() {
        if vc.isKind(of: TargetViewController.self) {
            minIndex = index
            break
        }
    }
    if minIndex != 0 {
        tmp.removeSubrange((minIndex)..<(tmp.count - 1))
        self.navigationController?.viewControllers = tmp
    }

注:
1.swift5.0
2.minIndex初始值可以根据需求自定义

OC版参考:Caiflower->https://www.jianshu.com/p/66c41c6d9c8f

你可能感兴趣的:(侧滑返回至指定控制器(swift))