Remove annotation from MKMapView which is in another view
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;
[appDelega开发者_如何学编程te.ridesMap removeAnnotation: ano];
[appDelegate release];
I must be trying to access the MKMapView
of my other view incorrectly?
- 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.)
精彩评论