簡體   English   中英

iOS - 在MKAnnotationView上設置詳細信息披露按鈕

[英]iOS - Set Detail Disclosure Button on MKAnnotationView

我的MapViewController中有以下方法:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
    if (!annotationView) {
        annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
        annotationView.canShowCallout = YES;
        annotationView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
        annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        // could put a rightCalloutAccessoryView here
    } else {
        annotationView.annotation = annotation;
        [(UIImageView *)annotationView.leftCalloutAccessoryView setImage:nil];
    }

    return annotationView;
} 

我相信它設置正確,但是當我的地圖正確地顯示我的帶有標題和副標題的注釋時,但它們沒有顯示詳細信息披露按鈕,我錯過了什么嗎?

另一件事是,在調試時,從不調用此方法,但注釋視圖顯示標題和副標題。

很可能沒有設置地圖視圖的delegate

如果沒有設置delegate或者你沒有實現viewForAnnotation方法,地圖視圖將創建一個默認的注釋視圖,它是一個帶有僅包含標題和副標題的標注的紅色圖釘(除非標題為空白,在這種情況下你是將獲得一個引腳,但沒有標注)。

將地圖視圖的delegate出口連接到文件所有者或在代碼中添加此項(例如,在添加注釋之前在viewDidLoad ):

mapView.delegate = self;

此外,如果您不使用ARC,請將autorelease添加到alloc行以避免內存泄漏。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM