2

ピン注釈に詳細ボタンを追加しました。別の景色に行きたい。それをクリックすると、次のコードが機能しません。どこに問題があるのか​​わからない。

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKPinAnnotationView *pinAnnotation = nil;
    if(annotation != mapview.userLocation)
    {
        static NSString *defaultPinID = @"myPin";
        pinAnnotation = (MKPinAnnotationView *)[mapview dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if ( pinAnnotation == nil )
            pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

        pinAnnotation.canShowCallout = YES;

        //instatiate a detail-disclosure button and set it to appear on right side of annotation
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinAnnotation.rightCalloutAccessoryView = infoButton;

    }

    return pinAnnotation;
}

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{

    if ([(UIButton*)control buttonType] == UIButtonTypeDetailDisclosure){
    annotationViewController *detailView=[[annotationViewController alloc] initWithNibName:@"annotationViewController" bundle:nil];

    [[self navigationController] pushViewController:detailView animated:YES];
    [detailView release];
}
}
4

1 に答える 1