- 遍历查找到目标控制器,执行 removeFromParentViewController 方法
# 注意:会出现navigationBar的title显示错乱问题
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[TargetViewController class]]) {
[vc removeFromParentViewController];
}
}
- 复制 navigationController.viewControllers 为可变数组,遍历 navigationController.viewControllers 查找到目标控制器,从可变数组中移除
NSMutableArray *mutableViewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[TargetViewController class]]) {
[mutableViewControllers removeObject:vc];
}
}
self.navigationController.viewControllers = mutableViewControllers;