-1

Hi everyone in an IBAction I have

ProfileViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ProfileViewController"];
    [self.navigationController popToViewController:viewController animated:YES];
    NSLog(@"tapped");

And then when I click the button, I see the "tapped" is logged but the view controller doesn't go?

Why does it not pop to the new view controller?

Thanks

rmaddy
  • 307,833
  • 40
  • 508
  • 550
tim blue
  • 138
  • 2
  • 13

1 Answers1

0

popToViewController goes backwards to a ViewController already on the navigation stack.

You need to use pushViewController

Jessica
  • 8,469
  • 12
  • 52
  • 100
chedabob
  • 5,757
  • 2
  • 25
  • 44
  • I have already been on the view controller I am trying to pop too. I am pushed to the current and want to go back 2 view controllers, but it is not the root. – tim blue May 15 '15 at 22:34
  • In that case you need a reference to the ViewController you want to pop to. In your code, you are instantiating a new instance of your VC. You can get the ViewController through the UINavigationController's viewControllers property – chedabob May 15 '15 at 22:38
  • Okay, can you show me what you mean about getting the VC thought the UINavigations viewController property? – tim blue May 15 '15 at 22:39
  • https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/#//apple_ref/occ/instp/UINavigationController/viewControllers – chedabob May 15 '15 at 22:41