Reputation: 21
I am new to iPhone apps, I have a problem with navigation controller at push and pop view, for example I have three views i,e A , B and C respectively, in that I am going(push) to A-->B-->C and also coming back (pop) C-->B-->A its working.
case 1: Now my requirement is as follows A->C then i need to move from C->B so how can i do this? in this case i'm using push(It's working).
case 2: But when i'm going A->B->C and coming back from C->B i need to use pop NOT Push. So How can use Push and pop operations in case1 sand case2. Now i'm writing in the following way.
// A-->C and C-->B or if [self.navigationController.viewControllers objectAtIndex:0]
I used this code:
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];
How can I compare whether the objectAtIndex:0
and objectAtIndex:1
Upvotes: 0
Views: 7841
Reputation: 1034
We welcome you, its not a problem that you are new, we are here to guide yu with proper solution, so dear fellow, first make some changes in appdelegate file which is:
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;
and after that use this code for pushing views:
ANYVIEWCONTROLLER *view = [self.storyboard instantiateViewControllerWithIdentifier:@"ANYVIEWZID"];
[ [self navigationController] pushViewController:view animated:YES];
Upvotes: 0
Reputation: 437
NSMutableArray *views=[NSMutableArray arrayWithArray:self.navigationController.viewControllers];
[views removeObjectAtIndex:[views count]-2];
self.navigationController.viewControllers=views;
[self.navigationController popViewControllerAnimated:YES];
try this change the value instead of 2 i think this will help you
Delete the stack values and move to the page you want to.......
thank you.....
Upvotes: 1
Reputation: 17877
Look at my example: (read comments =) )
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];
Upvotes: 0