Dave
Dave

Reputation: 923

How to go back to previous view in IOS?

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

Upvotes: 0

Views: 2405

Answers (1)

Michael
Michael

Reputation: 6907

Check your view controller hierarchy with the following code:

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

And try this method:

[self.navigationController popToRootViewControllerAnimated:YES];

Upvotes: 1

Related Questions