2011-12-31 8 views
0

通常、showuserlocationが有効になっていて、mapviewに行くと、青色の点がユーザーの現在の場所に動的に拡大されます。ただし、異なる色の目的のためにカスタム注釈ピンが作成されると、showuserlocation機能は消えます。 newAnnotation以下のコードは、犯人です。どのようにカスタムピンとshowuserlocation能力の両方を妨害していないのですか?カスタム注釈ピンがiphoneのmkmapviewのshowuserlocationに干渉する

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 

if ([[annotation title] isEqualToString:@"Destination"]) 
    { 
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"greenpin"]; 
newAnnotation.pinColor = MKPinAnnotationColorGreen; 
newAnnotation.animatesDrop = YES; 
newAnnotation.canShowCallout = YES; 
return newAnnotation; 
} 

} 

答えて

2

両方OPのこのコードは、コンパイラの警告になります「コントロールが非void型関数の終わりに達する可能性があり、」そう `の戻りはnilを追加する必要がありますが、この

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    // if it's the user location, just return nil. 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 

    if ([[annotation title] isEqualToString:@"Destination"]) 
    { 
     MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"greenpin"]; 
     newAnnotation.pinColor = MKPinAnnotationColorGreen; 
     newAnnotation.animatesDrop = YES; 
     newAnnotation.canShowCallout = YES; 
     return newAnnotation; 
    } 
} 
+0

を試してみてください;'非常に終わり。また、ARCを使用しない場合は、newAnnotationをautoreleaseする必要があります。 – Anna

関連する問題