0

モデルがあります:イベント、注釈ビューをマップビューにロードしましたが、選択した注釈からイベント管理オブジェクトを取得して、ビューコントローラーをプッシュしてイベントの情報を表示するにはどうすればよいですか。viewForAnnotation部分:

- (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;
}

およびrightCalloutAccessoryViewdisplayViewController部分:

- (void)displayViewController:(id)sender
{
    Annotation *annotation = [self.mapView selectedAnnotations][0];
    EventsViewController *eventsVC = [[EventsViewController alloc] init];
    eventsVC.event = ???
    [self.navigationController pushViewController:eventsVC animated:YES];
}

Annotation * annotation = [self.mapView selectedAnnotations] [0]から管理対象オブジェクトを取得する方法は?アノテーションでイベントを宣言した場合、どうなりますか?

4

1 に答える 1

0

The class Annotation is your own is it not? Does it contain a property for holding the event? If not then it should.

If you remove the custom selector you've assigned to rightButton and you've set the delegates correctly then you should get a call to this function

- (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 に答える