views:

202

answers:

1

Hello users,

I have implemented an app that shows a map with a lot of pins on it. If you push one pin you get on a second view that shows the data behind the pin. A button takes you back to the map.

My problem is that by the third touch on a pin the program crashes with a EXC_BAD_ACCESS in this method:

 - (void) switchViews {
     if(self.details == nil){
           Kundendetails *detailAnsicht = [[Kundendetails alloc] initWithNibName:@"ViewList" bundle:nil];
          detailAnsicht.rootViewController = self;
          self.details = detailAnsicht;
          detailAnsicht.map = self.map; 
     }
     if(self.details.view.superview == nil) {
          [map.view removeFromSuperview];
          [self.view addSubview:details.view];
          [details viewDidLoad];
     } else {
          [details.view removeFromSuperview];
          [details release];
          [self.view addSubview:map.view];
     }
}

How do I isolate which line of code causes the crash? Why would it always crash only on the third touch?

I hope you could help me.

+1  A: 

Put NSLog statements in each branch of the ifs. You will almost assuredly see that this statement causes the problem:

  [details viewDidLoad];

This is because at some point you execute this:

  [details release];

effectively making details inaccessible. By the way you should also almost NEVER call viwewDidLoad directly.

ennuikiller