Reputation: 5407
Currently I'm using the following code to find out if a view controller is in the navigation stack, and it's not the root one in the stack.
self.navigationController.viewControllers.count > 1
Is there any better solutions?
Upvotes: 1
Views: 1578
Reputation: 1033
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:([self.navigationController.viewControllers count]-2)] animated:YES];
Upvotes: 1
Reputation: 6703
If you convert what you describe directly to code, it'll be something like this.
NSUInteger index = [self.navigationController.viewControllers indexOfObject:self];
BOOL b = index != NSNotFound && index != 0;
The code you wrote may not work when your UINavigationController
is not at the top of the stack.
Upvotes: 3