self.navigationController遇到很多问题,如限制控制器的个数,跳转到根目录,跳转指定页面,多次跳转等问题,下面对其做了些总结,方便后期需要
通过计算viewcontrollers容器中控制器的个数来,限制推控制器的个数
if (self.navigationController.viewControllers.count > 3) {
//当推到第三个时,不允许继续推
[self.navigationController popViewControllerAnimated:YES];
//跳转到最原始的根目录
[self.navigationController popToRootViewControllerAnimated:YES];
return;
}
//返回根页面vc用 :
[self.navigationController popToRootViewController];
//返回指定的某个vc用下面(通过index定位)
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:2] animated:YES];
//或(通过class定位)
for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[FPHMyFindHouseVC class]]) {
[self.navigationController popToViewController:controller animated:YES]; }
}
//利用拿到的nav的controllers数组进行跳转
NSArray *vcs = self.navigationController.viewControllers;
NSMutableArray *array = [NSMutableArray array];
for (int i = 0; i < vcs.count; i++) {
UIViewController *temp = [vcs objectAtIndex:i];
[array addObject:temp];
if ([temp isKindOfClass:[FPHMyFindHouseVC class]]) {
break;
}
}
[array addObject:receiveViewController];
[self.navigationController setViewControllers:array animated:YES];
这是目前所遇到的一些问题汇总。