? ? ?
? ? ? ? // 返回跟控制器
? ? ? ? ?[self.navigationController popToRootViewControllerAnimated:YES];
? ? ?// ? ? 從導航push過去的視圖想要返回指定控制器時可以使用以下方法
? ? ? // ?第一種:
? ? ? ? ?//objectAtIndex后面的參數(shù)就是你想要返回的控制器在navigationController.viewControllers的下標
? ? ? ? [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES]
? ? ?// ?第二種: ?
? ? ? ?//UIViewController是指定的要返回的控制器
? ? ? for (UIViewController *controller in self.navigationController.viewControllers) {
? ? ? ?if ([controller isKindOfClass:[UIViewController class]]) {
? ? ? ?[self.navigationController popToViewController:controller animated:YES]; ??
? ? ? ?}
? ? ? }
? ? ? ?//切記:不可使用如下方法會導致崩潰
? ? ? UIViewController *VC = [[UIViewController alloc] init];
? ? ?[self.navigationController popToViewController:VC animated:YES];
? ?// ?崩潰信息如下:
? ? ? ?//Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Tried to pop to a view controller that doesn't exist.'