0

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?

4

1 回答 1

0

类注释是你自己的,不是吗?它是否包含用于持有的属性event?如果没有,那么它应该。

如果您删除了分配给 rightButton 的自定义选择器并且您已正确设置委托,那么您应该调用此函数

- (void)mapView:(MKMapView *)map annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    REVClusterPin *annotation = (REVClusterPin *)view.annotation;
    EventsViewController *eventsVC = [[EventsViewController alloc] init];
    eventsVC.event = annotation.event;
    [self.navigationController pushViewController:eventsVC animated:YES];

}
于 2013-02-17T08:34:30.967 回答