当跳转其他控制器时,有时需要删除指定上级控制器,通过对UIViewController控制器进行以下扩展,从而快速的删除控制器!
extension UIViewController {
/// - Parameter targetType: 指定控制器类型
open func removeSuperVC(_ targetType: UIViewController.Type) {
guard let vcs = navigationController?.viewControllers else {return}
guard let index = vcs.lastIndex(where: { $0 .isKind(of: targetType) }) else {return}
navigationController?.viewControllers.remove(at: index)
}
}
网友评论