0

I'm a bit weak in my Objective C I'll admit, my ultimate goal is pass data from ViewController3 back to ViewController1. Actually, that part is already done and successful. However when calling [self.navigationController popToRootViewControllerAnimated:YES] I get EXC_BAD_ACCESS.

ViewController1 <ViewController2Delegate>
- (void) didAddEventLocation:(Event *)event {
    NSLog(@"Event name = %@", event.name); //Shows name successfully
}

ViewController2 <ViewController3Delegate>
- (void) didAddEvent:(Event *)event {
   [self.delegate didAddEventLocation:event];
}

ViewController3
[self.delegate didAddEvent:event];
[self.navigationController popToRootViewControllerAnimated:YES];

Sorry for the poorly formatted code, just trying to simplify. Doing [self.navigationController popViewControllerAnimated:YES] has no problem, however it only takes me to ViewController2. I know I'm doing something very wrong here, but can't quite place my finger on how to resolve it. Let me know if I need to clarify.

xhermit
  • 501
  • 1
  • 7
  • 19

2 Answers2

2

Use Zombies to hunt down what is giving you the EXC_BAD_ACCESS. Some object has been released and is now being called on when you are popping back to the root view controller.

Try this link: How do I set up NSZombieEnabled in Xcode 4?

Community
  • 1
  • 1
ozz
  • 1,137
  • 7
  • 9
  • @xhermit Yeah, this have to solve your problem. You'll see which object was dealocated. – kaspartus Jan 13 '13 at 06:39
  • Thanks. I've used Instruments before to hunt down zombies, I guess I forgot I'm supposed to be looking for Event Type = Zombie in my stack trace. I tracked it down to a problem with not calling [self.locationManager stopUpdatingLocation] before popping my navigation stack. Thanks again! – xhermit Jan 13 '13 at 19:13
1

Looks like, that one of your you controllers(first in my opinion) is deallocated. In VC3 method check that self.navigationController exists. Then you have to check all his VCs. I think that nothing holding first VC. Problem may be solved by using(for example) addChildViewController method of your navigation controller, or if smth will have a reference to your controllers.

Also, you can use NSNotificationCenter to send some information from one instance to another if you have problems with path between them.

HTH!

kaspartus
  • 1,365
  • 15
  • 33
  • [self.navigationController.viewControllers objectAtIndex:x] shows the viewControllers as I'd expect them on the stack. – xhermit Jan 12 '13 at 23:39