0

I get a EXC_BAD_ACCESS error message in my AppDelegate.m program when I attempt to goback to the previous view controller by popping the current view controller off the stack. The error obviously means that the viewcontroller is not in the stack.

My code for initializing my first view in my AppDelegate.m program is as follows:

  CEMMainViewController *mc = [[CEMMainViewController alloc]     
                              init];       
  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mc];
  self.window.rootViewController = navController;

When I want to bring up a new view controller I do the following:

  CEMUpdateBurialViewController *oc = [[CEMUpdateBurialViewController  alloc] init];
  [self.navigationController pushViewController:oc animated:YES];

When I want to return to the previous view I do the following which causes the EXEC_BAD_ACCESS error. So why isn't the previous view in the stack? I just need to know what I am doing wrong.

  UINavigationController *navigationController = self.navigationController;
             [navigationController popViewControllerAnimated:YES];
Dave
  • 873
  • 2
  • 15
  • 27
  • try just like CEMMainViewController *mc = [[CEMMainViewController alloc] initwithnibname:"your XIb name"]; – Maulik shah Oct 26 '14 at 03:23
  • Thanks for your reply. I just pushed my previous view back on the stack instead of popping off the current view which works but is not as efficient as just using the back button. – Dave Oct 26 '14 at 04:01
  • That's not a good thing to do, as you will keep adding more and more controllers to your stack that way. Try commenting out all the code in CEMUpdateBurialViewController and see if you still get the error when you hit the back button. – rdelmar Oct 26 '14 at 04:02
  • if you want to pop then just try [self.navigationController popToRootViewController Animated:YES]; – Maulik shah Oct 28 '14 at 04:06

1 Answers1

1

Check your view controller hierarchy with the following code:

 NSLog(@"%@",self.navigationController.viewControllers);

And try this method:

[self.navigationController popToRootViewControllerAnimated:YES];
Michael
  • 6,561
  • 5
  • 38
  • 55