1

デリゲート内に次のコードがあります。

     - (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)anAnnotation 
{
    MKPinAnnotationView *pin = (MKPinAnnotationView *) [map dequeueReusableAnnotationViewWithIdentifier: @"RoutePin"];
    if (pin == nil)
    {
        if ([anAnnotation isKindOfClass:[RouteMapAnnotation class]])
        {
            RouteMapAnnotation *theAnnotation = (RouteMapAnnotation *)anAnnotation;
            if (theAnnotation.identifier == @"routePin")
            {
                //NSLog(@"TESTING PART III");
                MKPinAnnotationView *startAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:anAnnotation reuseIdentifier:@"RoutePin"];
                UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                startAnnotationPin.canShowCallout = YES;
                startAnnotationPin.animatesDrop = YES;

                startAnnotationPin.rightCalloutAccessoryView = rightButton;
                startAnnotationPin.pinColor = MKPinAnnotationColorRed;
                return startAnnotationPin;
            }
            else if (theAnnotation.identifier == @"finishPin")
            {
                NSLog(@"CREATING FINISH FLAG PRIOR");
                MKPinAnnotationView *finishAnnotationPin = [[MKPinAnnotationView alloc] initWithAnnotation:anAnnotation reuseIdentifier:@"FinishPin"];
                finishAnnotationPin.canShowCallout = NO;
                finishAnnotationPin.animatesDrop = YES;
                //finishAnnotationPin.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://cdn4.iconfinder.com/data/icons/formula1/f1_png/128/checkered_flag.png"]]];
                finishAnnotationPin.image = [UIImage imageNamed:@"flag_finish"];
                return finishAnnotationPin;

            }
        }
    }
    return nil;
}

ただし、地図上にピンの画像は表示されていません。何が足りないの?

4

2 に答える 2

1

MKPinAnnotationViewの代わりにMKA​​nnotationViewを使用する必要があります。

ピン注釈はピン用です。

于 2011-03-16T18:05:41.317 に答える
0

また、MKPinAnnotationViewは、ドラッグ中のアニメーションや3Dシャドウ効果など、通常のMKAnnotationViewにいくつかの追加機能を提供することにも注意してください。MKAnnotationViewを使用する場合、これらは取得されません。

これらの組み込み機能が必要な場合は、UIImageViewを作成し、それをサブビューとしてMKPinAnnotationViewに追加できます。これにより、好きなように見える注釈が付けられます。しかし、ピンのように動作します。ピンの頭を自分の画像に置き換えるために使用します。

于 2011-03-16T18:10:29.860 に答える