//侧滑返回至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初始值可以根据需求自定义