目标:当我触摸“fourthViewController”按钮时,它会检查“secondViewController”是否放在viewController堆栈中,而不使用“objectAtIndex:x”。如果存在,它会弹出视图控制器,直到第二个ViewController位于顶部。
目前的结果:
2014-03-11 10:44:54.187 Test_Push[320:11303] (
"<HomeViewController: 0x7153bd0>",
"<secondViewController: 0x71636c0>",
"<thirdViewController: 0x71648e0>",
"<fourthViewController: 0x7128b60>"
)
答案 0 :(得分:0)
我不完全确定我理解你的要求,但是如果你想检查secondViewController是否在viewControllerStack中,请执行以下操作:
NSArray * viewControllerStack = // I'm assuming you have array here
if ([viewControllerStack containsObject:secondViewController]) {
// 'secondViewController' in viewControllerStack
// Pop secondViewController here
}
else {
// 'secondViewController' NOT in viewControllerStack
// do other stuff
}
答案 1 :(得分:0)
试试这个,
for (UIViewController *viewcontroller in [self.navigationController viewControllers]) {
if ([viewcontroller isKindOfClass: [secondViewController class]]){
[self.navigationController popToViewController:viewcontroller animated:YES];
}
}
答案 2 :(得分:0)
尝试这些解决方案:
for(int i=0;i<[[self.navigationController viewControllers]count];i++)
{
NSLog(@"%@",[[self.navigationController viewControllers]objectAtIndex:i]);
if([[[self.navigationController viewControllers]objectAtIndex:i] isKindOfClass:[secondViewController class]]){
[[self navigationController]popToViewController:[[self.navigationController viewControllers]objectAtIndex:i] animated:YES];
}