Reputation: 13240
Is there any way to push a view controller to the navigation controller without stacking it?
Wanted behavior (stack representation):
[VC1[VC2]] -> Push VC3 from VC2 -> [VC1[VC3]]
Upvotes: 4
Views: 2454
Reputation: 9977
Yeah, just pop the other one before (without animating this one) like this:
[navController popViewControllerAnimated:NO]
[navController pushViewController:VC3 animated:YES]
Or go for option 2, which is more general: Replace the viewControllers property:
NSArray *newControllers = @[VC1, VC3];
[navController setViewControllers:newControllers animated:YES];
or...
NSArray *newControllers = @[navController.viewControllers[0], VC3];
[navController setViewControllers:newControllers animated:YES];
Upvotes: 7
Reputation: 1814
I would make use of UINavigationController's method:
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
That way you can do this:
UINavigationController *navigationController = [self navigationController];
[navigationController setViewControllers:@[navigationController.viewControllers[0], VC3] animated:YES];
This will give you a push animation to the new view controller (VC3).
Upvotes: 1