2010-04-05 18 views
4

在我的viewForAnnotation委託中,我創建了一個MKAnnotationView,其中leftCalloutaccessory作爲信息按鈕。當點擊信息按鈕時,我想用UIActivityIndicator替換它。因此,在calloutAccessoryTapped代表中,我寫了 view.leftCalloutaccessoryView = [UIActivityIndicator indicatorWithStyle:UIActivityIndicatorWhite];替換mkannotationview中的calloutaccessoryview

標註附件似乎發生了變化,但似乎視圖並未立即更新。

當標註附件被隱藏(通過點擊另一個針)並重新打開時,我看到一個微調框。但除此之外,我不知道。

我嘗試撥打[view setNeedsdisplay][view setNeedsLayout][view layoutsubviews],但徒勞無功。

任何建議/指針?

回答

0

我會考慮刪除並重新添加您的註釋。這似乎有點沉重,但可能有效。

0

我有一個類似的問題 - 我需要爲leftCalloutAccessoryView顯示一個圖像,如果有一個與註釋相關聯。嘗試在mapView:didSelectAnnotationView中設置它,而不是在mapView中:viewForAnnotation

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)annotView 
{ 
    ... 

    if(imgURL.length>1){    
     // set a thread that will load the image 
     // but don't set the leftCalloutAccessoryView until the image is loaded 
     dispatch_queue_t downloader = dispatch_queue_create("annotation image downloader",NULL); 
     dispatch_async(downloader, ^{ 
      NSURL* photoURL = [NSURL URLWithString:imgURL]; 
      NSData* photoData = [NSData dataWithContentsOfURL:photoURL]; 
      UIImage* photoImage = [UIImage imageWithData:photoData]; 
      dispatch_async(dispatch_get_main_queue(), ^{ 
       annotView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; 
       [(UIImageView *) annotView.leftCalloutAccessoryView setImage:photoImage]; 
      });     
     }); 
    } 
}