views:

265

answers:

1

I have two views. The first is a MKMapView with some annotations. Clicking a UIButton pushes a second view on the stack. This has a UITableView with a list of annotations which correspond to the map annotations. So, when you click the delete button, how can I call my MKMapView which is in another view, so that I can remove the annotation. My MKMapView is declared in my app delegate, as well as my current class. I am trying to use the following, but it is not working:

        RideAppDelegate *appDelegate = (RideAppDelegate *)[[UIApplication sharedApplication] delegate];
        Annotation *ano;
        CLLocationCoordinate2D anoPoint;
        anoPoint.latitude = [[eventToDelete valueForKey:@"latitude"] doubleValue];
        anoPoint.longitude = [[eventToDelete valueForKey:@"longitude"] doubleValue];
        ano = [[[Annotation alloc] init] autorelease];
        ano.coordinate = anoPoint;
        [appDelegate.ridesMap removeAnnotation: ano];
        [appDelegate release];

I must be trying to access the MKMapView of my other view incorrectly?

+1  A: 
  • ridesMap must be the MKMapView which must be an ivar of appDelegate. Is it a property with (retain)? Is it created and assigned with self.ridesMap = [[MKMapView alloc] init] or similar?
  • You are sure Annotation follows MKAnnotation protocol?

(why release the appDelegate? You don't own or retain it.)

Adam Eberbach
Yes, I am sure that Annotation follows MKAnnotation protocol, as I am able to create annotations using that. ridesMap is a property with retain. Where should I create it and alloc MKMapView like you showed above?
Nic Hubbard
If it needs to be a property in your appDelegate, probably you should create it in applicationDidFinishLaunching. If it's not a live object you can't use a method on it.
Adam Eberbach