在开发中 经常会有这样的需求,要求app 在完成某些操作以后 返回到某一界面 ,下面是我常用到的两种方法;
//方法一: 返回到制定界面 但不是根界面的某个界面
UserSettingViewController *homeVC = [[UserSettingViewController alloc] init];
UIViewController *target = nil;
for (UIViewController * controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[homeVC class]]) {
target = controller;
}
}
if (target) {
[self.navigationController popToViewController:target animated:YES];
}
方法二:返回到根界面上的某个界面
self.navigationController.tabBarController.hidesBottomBarWhenPushed=NO;
self.navigationController.tabBarController.selectedIndex=0;
[self.navigationController popToRootViewControllerAnimated:YES];
方法三:返回上两级页面
if (self.navigationController.viewControllers.count >= 2) {
UIViewController *vc = [self.navigationController.viewControllers objectOrNilAtIndex:1];
[self.navigationController popToViewController:vc animated:YES];
}