0

MKAnnotation に問題があります。カスタム pinview を使用すると、最初の読み込みで問題なく動作します。ピンを削除してから、色が変わる同じピンをリロードします。2 つの異なる DB からピンを追加すると、問題なく動作します。削除してから各配列を個別に追加すると、2 番目の配列は、割り当てられたものではなく、最初の配列のカスタム ピンを取得します。

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

MKAnnotationView *pinView = nil; 
if(annotation != mapView.userLocation) 
{
    static NSString *defaultPinID = @"pin";
    pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinView == nil ) 
        pinView = [[MKAnnotationView alloc]
                   initWithAnnotation:annotation reuseIdentifier:defaultPinID];

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [rightButton addTarget:self
                    action:@selector(showDetails:)
          forControlEvents:UIControlEventTouchUpInside];
    pinView.rightCalloutAccessoryView = rightButton;

    UIImageView *profileIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"stores.png"]];
    pinView.leftCalloutAccessoryView = profileIconView;

    NSString *badgestringss = @"8 reviews";
    customBadge1 = [CustomBadge customBadgeWithString:badgestringss 
                                      withStringColor:[UIColor whiteColor]
                                       withInsetColor:RGB(255, 51, 0)
                                       withBadgeFrame:YES 
                                  withBadgeFrameColor:[UIColor whiteColor] 
                                            withScale:1.0
                                          withShining:YES];
    [customBadge1 setFrame:CGRectMake(100, 1, 85, 15)];
    [pinView.leftCalloutAccessoryView addSubview:customBadge1];



    if(setStoreOrShops==NO){
    pinView.image = [UIImage imageNamed:@"stores.png"];    //as suggested by Squatch  
    }
    else if (setStoreOrShops==YES){
         pinView.image = [UIImage imageNamed:@"shops.png"];   
    }


   else {
    [mapView.userLocation setTitle:@"Current Location"];
}
     }
return pinView;
}

あちこち検索しましたが、機能する例や、これが壊れている場所のアイデアが得られないようです。助けてくれてありがとう。

4

2 に答える 2

1

この方法で修正しました

MyAnnotation *myAnnot = (MyAnnotation *)annotation;

if (myAnnot.mappin == @"42")
    customPinView.image = [UIImage imageNamed:@"shops.png"];
else
    customPinView.image = [UIImage imageNamed:@"stores.png"];   
于 2012-05-22T21:17:50.763 に答える
1

CustomBadge コードが何をするのか、または画像がどのように見えるのかがわからないため、色を変更するという意味がわかりません。ただし、問題は、ビューの初期設定内で条件付きロジックを適用している可能性があります。後で dequeReusableAnnotationViewWithIdentifier: が実際に何かを返すとき、それは別のもののために構成されています。

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

    MKAnnotationView *pinView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"default"];
    if (pinView == nil) {
        // CONFIGURE ONCE
        // things that are set up once and never change
    }

    // CONFIGURE EVERY VIEW
    // view configurations that change every pin
}

画像を設定するコードを「一度構成」セクションから取り出し、「ビューごとに構成」セクションに配置する必要があります。そうしないと、再利用可能なビューをデキューする呼び出しを行うたびに、誤って構成されたものを取得する可能性があります。

于 2012-05-21T21:28:28.677 に答える