I have a model: Event, I have loaded the annotation view to the mapview, but how do I get the event managed object from the selected annotation, so I can push a view controller to display event's info. The viewForAnnotation part:
- (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if([annotation class] == MKUserLocation.class) {
//userLocation = annotation;
return nil;
}
REVClusterPin *pin = (REVClusterPin *)annotation;
MKAnnotationView *annView;
annView = [aMapView dequeueReusableAnnotationViewWithIdentifier:@"pin"];
if( !annView )
annView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"pin"];
annView.image = [UIImage imageNamed:@"pinpoint.png"];
annView.canShowCallout = YES;
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(displayViewController:) forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = rightButton;
annView.calloutOffset = CGPointMake(-6.0, 0.0);
}
return annView;
}
and the rightCalloutAccessoryView displayViewController part :
- (void)displayViewController:(id)sender
{
Annotation *annotation = [self.mapView selectedAnnotations][0];
EventsViewController *eventsVC = [[EventsViewController alloc] init];
eventsVC.event = ???
[self.navigationController pushViewController:eventsVC animated:YES];
}
How to get the managed object from Annotation *annotation = [self.mapView selectedAnnotations][0] ? If I declare a event in Annotation, then what?