pop控制器

时间:2022-02-25 10:48:52

1.寻找指定的控制器MineViewControllerclass

UIViewController *mineVC = nil;

for (UIViewController * controllerin self.navigationController.viewControllers) {//遍历

if ([controller isKindOfClass:[MineViewControllerclass]])

{ //这里判断是否为你想要跳转的页面

mineVC = controller;

}

}

2.pop到相应的控制器

//返回到指定的控制器,要保证前面有入栈。

int index = (int)[[self.navigationController viewControllers]indexOfObject:self];

if (index>2) {

//返回上上级控制器

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(index-2)] animated:YES];

}else

{

//返回到根控制器

[self.navigationController popToRootViewControllerAnimated:YES];

}