https://blog.csdn.net/ws1352864983/article/details/52964889ios
ios中 viewcontroller的跳轉問題,其中有一種方式是採用
navigationController pushViewController
的方法,可能會從主頁面跳轉到了一級頁面,又從一級頁面跳轉到了二級頁面,而後從二級頁面跳轉到了三級頁面,依次類推。,等等。spa
[self.navigationController popViewControllerAnimated:Yes];
不少狀況下可能想要立刻回到主頁面,而不是一級一級的返回,或者直接返回pop出N個界面..net
[self.navigationController popToRootViewController]
返回指定的某級Nvc用下面code
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:N] animated:YES];
或指定控制器blog
//遍歷控制器 for (UIViewController *controller in self.navigationController.viewControllers) { if ([controller isKindOfClass:[你要跳轉到的Controller class]]) { [self.navigationController popToViewController:controller animated:YES]; } }
int index = (int)[[self.navigationController viewControllers]indexOfObject:self]; [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(index -2)] animated:YES];