It is not entirely clear how your views are set up with respect to each other, based on what you've said so far.
I'm guessing you have a navigation controller, and 3 view controllers that are displayed on the navigation stack.
If that's the case, and you want to pop back by two screens at once (from #3 to #1, skipping #2), then you need a pointer to the view controller for #1 (not the view itself). It looks as if the first popViewController:
method call in your question is sending in a view.
Sample code to pop to the first view controller:
UINavigationController* navController = self.navigationController;
UIViewController* controller = [navController.viewControllers objectAtIndex:0];
[navController popToViewController:controller animated:YES];
If you've tried this, and it doesn't work, a few things might be going wrong:
- Maybe
self.navigationController
isn't actually the right object.
- Maybe the view you expect isn't actually view #0 on the navigation stack.
- Maybe the navigation controller you're working with isn't currently visible.
Here are some further steps you can take to test these hypotheses:
- When you first allocate the navigation controller you want to work with, call
NSLog(@"Nav controller is at %p", navController);
and in this code add a call to NSLog(@"Now my navController is at %p", navController);
and check that the addresses match.
If the nav controller is the right one, print out the current navigation stack; something like this (which assumes each view controller has a different class name):
for (UIViewController* viewController in navController.viewControllers) {
NSLog(@"%s", class_getName([viewController class]));
}
Do something visual to the navigation controller you think is visible to make sure it actually is. For example [navController.visibleViewController.view addSubview:aColorFulView];
where aColorFulView
is some visually obvious UIView
.