Question

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?

Was it helpful?

Solution

  • 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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top