views:

411

answers:

3

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.

+1  A: 

-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];

Ben Gottlieb
+2  A: 

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.

Tyler
this actually very helpful let me try to follow up on this - thank you this is good, even if I don't get around to find out what's going on because of my lack of knowledge.
amok
A: 

If your need real jumping instead of pushing views, look at this uiview jumping animation sample.

slatvick
thank you this was helpful to close the loop
amok