Reputation: 1745
I have 3 views (xib'd) the third view opens a modal view (also xib'd). My goal is to dispose the modal view and jump on the view #1.
I used the following code but it does nothing.
self.statusView = [[StatusViewController alloc] initWithNibName:@"StatusViewController" bundle:nil];
[self.navigationController popToViewController:self.statusView animated:YES];
[self.navigationController popToViewController:
I also tried the following, same result. [self.navigationController.viewControllers objectAtIndex:0] animated:YES];
I'm going crazy...
statusView has an accessor regularly synthetized and it represents the view that I want to jump to.
Upvotes: 2
Views: 3576
Reputation: 28864
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:
self.navigationController
isn't actually the right object.Here are some further steps you can take to test these hypotheses:
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
.
Upvotes: 7
Reputation: 85522
-popToViewController lets you pop controllers OFF the stack. What you want to do is push new viewControllers ONTO the stack, so use:
[self.navigationController pushViewController: self.statusView animated: YES];
Upvotes: 1