NavigationController.viewControllers
NSMutableArray *viewControllersArray = [NSMutableArray new];
// 获取当前控制器数组
for (CardLoanBaseTableViewController *viewController in self.navigationController.viewControllers) {
[viewControllersArray addObject:viewController];
if ([viewController isKindOfClass:[self class]]) {
break;
}
// 获取当前控制器数组
for (CardLoanBaseTableViewController *viewController in self.navigationController.viewControllers) {
[viewControllersArray addObject:viewController];
if ([viewController isKindOfClass:[self class]]) {
break;
}
}
获取到数组之后,可以对数组进行添加删除等操作,之后重新设定nav数组!
尽量少用firstObject啥的,以防之后修改代码还需要重新设定!
[self.navigationController setViewControllers:viewControllersArray animated:YES];
1.使用此代码,并享受:
NSMutableArray *navigationArray = [[NSMutableArray alloc] initWithArray: self.navigationController.viewControllers];
// [navigationArray removeAllObjects]; // This is just for remove all view controller from navigation stack. [navigationArray removeObjectAtIndex: 2]; // You can pass your index here self.navigationController.viewControllers = navigationArray;
2. 你可以先获取数组中的所有视图控制器,然后用相应的视图控制器类检查后,你可以删除你想要的下面是一小段代码:
3. 如果你正试图从第五视图控制器(跳过第3和第4)移动到第二个视图控制器,你想
[self.navigationController popToviewController:secondViewController] ,可以你得到secondViewController 从导航控制器堆栈。
- (NSEnumerator *)reverseObjectEnumerator
按照索引号从大到小访问数组的元素,而不是从小到大访问数组的元素。
|