2011-07-03 6 views
0

私は両方この(MKMapViewの委任)試してみた:MKAnnotationViewをサブクラス化されたMKMapViewでのみカスタマイズしますか?

-(void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views 
{ 
    for (MKAnnotationView *annotationView in views) 
    { 
     annotationView.image = [UIImage imageNamed:@"itemType2.png"]; 
     annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     annotationView.canShowCallout = YES; 
    }   
} 

と、この(MKMapViewを持っているVC上):MKAnnotationViewの外観を変更することで任意の成功は、彼らが表示されwhithout

[self.theMapView addAnnotations:annotationsArray]; 

for (id <MKAnnotation> itemAnnotation in self.theMapView.annotations) 
{   
    MKAnnotationView *itemAnnotationView = [self.theMapView viewForAnnotation:itemAnnotation]; 

    itemAnnotationView.image = [UIImage imageNamed:@"itemType2.png"]; 
    itemAnnotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    itemAnnotationView.canShowCallout = YES; 

    //[self.theMapView setNeedsDisplay]; 
} 

開示ボタンなどのない単純な赤いピンとして...

サブクラス化されたMKMapViewを作成し、 - (MKAnnotationView *)viewForAnnotation:(id < MKAnnotation> )注釈???注釈を変更するためだけに余分なサブクラスを作成する必要はないと思いますが、なぜ上記のメソッドは機能しませんか?

答えて

3

MKAnnotationViewでこれらのプロパティを設定するために何かをサブクラス化する必要はありません。

viewForAnnotationデリゲートメソッドを実装し、そこにプロパティを設定する必要があります。

コード例については、this answerを参照してください。

MKPinAnnotationViewの代わりにMKAnnotationViewを使用するだけです。

関連する問題