簡體   English   中英

iphone - MKMapView 標注不會顯示在帶有 iOS 4.1 的 iPhone 4 上

[英]iphone - MKMapView callout doesn't show on iPhone 4 with iOS 4.1

我對 MKMapView 有疑問。 我添加這樣的注釋:

// set up new points
for(int i = 0; i < [_locations count]; i++) {
    PPlace * place = [_locations objectAtIndex:i];
    PlaceAnnotation * placeAnnotation = [[PlaceAnnotation alloc] initWithPlace:place];
    // if annotation is for currently selected place
    placeAnnotation.isCurrent = i == currentIndexPath.row;
    [self.mapView addAnnotation:placeAnnotation];
    if (placeAnnotation.isCurrent) {
        [self.mapView selectAnnotation:placeAnnotation animated:YES];
    }
    [placeAnnotation release];
}

因此,我嘗試在添加后立即顯示標注 bouble,而不是在點擊注釋引腳后。 在模擬器中一切正常,在帶有 iOS 4.3.2 的 iPhone 3GS 上也是如此。 但是,標注不會在帶有 iOS 4.1 的 iPhone 4 上顯示(它們僅在點擊引腳后顯示)。 知道如何解決這個問題嗎?

我的猜測是您沒有為注釋 class 的標題屬性分配值。 即使您可以將canShowCallout設置為YES ,除非您的標題中有內容,否則標注氣泡不會顯示。

您將需要實現以下方法:

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

你可以在這里找到文檔

你在錯誤的時間調用它。 在加載之前,您不能 select 它。

使用 MKMapView 的委托方法:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views

從該方法調用內部:

[yourMapView selectAnnotation: yourAnnotation animated: YES];

嘗試添加

placeAnnotation.canShowCallout = YES;

所以它看起來像:

// set up new points
for(int i = 0; i < [_locations count]; i++) {
    PPlace * place = [_locations objectAtIndex:i];
    PlaceAnnotation * placeAnnotation = [[PlaceAnnotation alloc] initWithPlace:place];
    // if annotation is for currently selected place
    placeAnnotation.isCurrent = i == currentIndexPath.row;
    [self.mapView addAnnotation:placeAnnotation];
    if (placeAnnotation.isCurrent) {
        [self.mapView selectAnnotation:placeAnnotation animated:YES];
        placeAnnotation.canShowCallout = YES;
    }
    [placeAnnotation release];
}

希望這可以幫助! 威薩姆

暫無
暫無

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

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