栈管理总结
1、基本的入/出栈
// 进
[self.navigationController pushViewController:resCtr animated:YES];
// 出
[self.navigationController popViewControllerAnimated:YES];
2、查找栈(查)
NSMutableArray *marr = [[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
for (UIViewController *vc in marr) {
if ([vc isKindOfClass:NSClassFromString(@"WantClass")]) {
NSLog(@"找到了")
break;
}
}
3、进入/返回到指定栈
// 进
[self.navigationController popToViewController:Ctr animated:YES];
// 出
NSMutableArray *marr = [[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
for (UIViewController *vc in marr) {
if ([vc isKindOfClass:NSClassFromString(@"WantClass")]) {
[self.navigationController popToViewController:vc animated:YES];
break;
}
}
4、在指定位置插入指定栈(增)
NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
for (int i = 0; i < viewControllers.count; i++){
id vc = viewControllers[i];
if ([vc isKindOfClass:[GCWKWebViewController class]]){
UIViewController *insertVC = [[NSClassFromString(@"WantClass") alloc] init];
[viewControllers insertObject:insertVC atIndex:i + 1];
[self.navigationController setViewControllers:viewControllers animated:NO];
// [self.navigationController popToViewController:insertVC animated:YES];
break;;
}
}
5、删除指定栈(删)
NSMutableArray *viewControllers = [[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
for (UIViewController *vc in viewControllers) {
if ([vc isKindOfClass:NSClassFromString(@"WantClass")]) {
[viewControllers removeObject:vc];
break;
}
}
self.navigationController.viewControllers = viewControllers;
6、更改指定栈(改)
NSMutableArray *viewControllers = [[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
for (UIViewController *vc in viewControllers) {
if ([vc isKindOfClass:NSClassFromString(@"WantClass")]) {
UIViewController *replaceVC = [[NSClassFromString(@"WantClass") alloc] init];
[viewControllers replaceObjectAtIndex:i withObject:replaceVC];
break;
}
}
self.navigationController.viewControllers = viewControllers;