我是iPhone应用的新手,导航控制器出了问题 在推和弹出视图中,例如我有三个视图i,e A,B和C. 我将分别(推)到A - > B - > C并且即将到来 back(pop)C - > B - > A工作。
案例1:现在我的要求是 跟随A-> C然后我需要从C-> B移动所以我该怎么做?在 这种情况我正在使用推(它正在工作)。
案例2:但是当我要去的时候 A-> B-> C并且从C-> B返回我需要使用pop NOT Push。又怎样 可以在case1 sand case2中使用Push和pop操作。现在我正在写作 通过以下方式。
// A-->C and C-->B or if [self.navigationController.viewControllers objectAtIndex:0]
我使用了这段代码:
CategoryClass *class=[[CategoryClass alloc]initWithNibName:@"CategoryClass" bundle:nil];
[self.navigationController pushViewController:class animated:YES];
// A-->B-->C(push) for back C-->B or if [self.navigationController.viewControllers objectAtIndex:1] i want to use this code
[self.navigationController popViewControllerAnimated:YES];
如何比较objectAtIndex:0
和objectAtIndex:1
答案 0 :(得分:1)
NSMutableArray *views=[NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[views removeObjectAtIndex:[views count]-2];
self.navigationController.viewControllers=views;
[self.navigationController popViewControllerAnimated:YES];
尝试更改值而不是2我认为这会帮助你
删除堆栈值并移至您想要的页面.......
谢谢.....答案 1 :(得分:0)
看看我的例子:(读评论=))
UINavigationController *navController;
UIViewController *viewControllerA, *viewControllerB, *viewControllerC;
[navController pushViewController:viewControllerA animated:YES]; // -> A
// some time passed
NSArray *currentViewControllers = [navController viewControllers]; // <- on stack now
NSMutableArray *newStack = [NSMutableArray arrayWithArray:currentViewControllers];
[newStack addObject:viewControllerB]; // <- adding B
[newStack addObject:viewControllerC]; // <- adding C
[navController setViewControllers:newStack animated:YES]; // <- setting new view controllers stack: A, B, C
// returning to B: pop viewControllerC
[navController popViewControllerAnimated:YES];
// or
[navController popToViewController:viewControllerB animated:YES];
答案 2 :(得分:0)
我们欢迎您,这不是您是新手的问题,我们在这里为您提供适当的解决方案, 亲爱的家伙,首先在appdelegate文件中进行一些更改:
storyboardName = [AppHelper isPhone] ? @"Main_iPhone" : @"Main_iPad";
storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
navController = (UINavigationController*)[storyboard instantiateInitialViewController];
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
MainMenu *controller = (MainMenu*)[mainStoryboard instantiateViewControllerWithIdentifier: @"MainMenuiphone"];
[navigationController pushViewController:controller animated:NO];
self.window.rootViewController = navigationController;
之后使用此代码来推送视图:
ANYVIEWCONTROLLER *view = [self.storyboard instantiateViewControllerWithIdentifier:@"ANYVIEWZID"];
[ [self navigationController] pushViewController:view animated:YES];