2011-06-14 43 views
4

我有一個MKMapView的問題。我添加註釋這樣的:iPhone - MKMapView標註不會顯示在iOS 4.1的iPhone 4上

// 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]; 
} 

所以我試圖顯示標註布布爾河立即加入後,不經過註解引​​腳被竊聽。 一切工作正常,在模擬器上,也在iPhone 3GS與iOS 4.3.2。但是,標註不會顯示在帶有iOS 4.1的iPhone 4上(它們僅在插入引腳後才顯示)。任何想法如何解決這個問題?

+0

我有同樣的問題。 – InsertWittyName 2011-06-14 08:16:46

+1

你可以發佈你的'PlaceAnnotation'實現嗎?也許title屬性返回一個空字符串。 – yinkou 2012-07-04 08:03:43

+0

你需要在你的註解對象上設置'title'屬性。 – 2015-08-03 17:55:37

回答

0

嘗試添加

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]; 
} 

希望這有助於! WeSaM

+0

它不會工作,因爲placeAnnotation不是從MKAnnotationView派生的。它只是NSObject的一個子類。 – Marcin 2011-06-24 14:35:46

+0

我也有類PlaceAnnotationView,它是MKAnnotationView的子類,在 - (MKAnnotationView *)mapView:(MKMapView *)中創建mapView viewForAnnotation:(id )註釋,並且我在那裏設置了canShowCallout = YES。它不起作用。 – Marcin 2011-06-24 14:37:36

+1

在'MKPointAnnotation'對象上設置標題,用於表示引腳數據結構。 – 2015-08-03 17:55:00

1

我的猜測是您沒有爲您的註記類的title屬性賦值。即使您可能將canShowCallout設置爲YES,但除非您的標題中有內容,否則將不會顯示調出泡泡。

+0

我確實分配了標題和副標題。如果我不願意,標註將永遠不會出現,如果在模擬器或設備上無所謂。但它確實出現在例如模擬器上,或者在具有iOS 4.3.2的iPhone 3GS上。 – Marcin 2011-06-27 10:00:21

0

您需要實現以下方法:

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

你可以找到你在錯誤的時間調用它的文檔here

0

。直到加載後才能選擇它。

使用的MKMapView的委託方法:

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

,並從該方法調用的內部:

[yourMapView selectAnnotation: yourAnnotation animated: YES];