2011-09-13 33 views
0

我正在使用帶有許多註釋的MKMapView。一切都還好,直到我放大和縮小我的地圖。一些註釋的位置相互切換。有人知道爲什麼 這裏是我調用viewDidLoad從3個數組導入註釋的代碼:經度,緯度和photoFileName。 photoFileName包含所有註釋的照片文件名稱,經度和緯度包含它們的座標。MKMapview註釋在放大和縮小後出錯

for (int i=0; i<[longitudes count]; i++) 
CLLocation* location = [[CLLocation alloc] initWithLatitude:[latitudes objectAtIndex:i] 
      longitude:[longitudes objectAtIndex:i]]; 
CSMapAnnotation* annotation = [[CSMapAnnotation alloc] initWithCoordinate:[location coordinate] 
      annotationType:CSMapAnnotationTypeImage 
      title:@""; 
      subtitle:@""; 

// Set data for the annotation. This data is used for displaying annotation 
[annotation setUserData:[photoFilename objectAtIndex:i]]; 

[_mapView addAnnotation:annotation]; 
[annotation release]; 
[currentLocation release]; 

}

一切OK加載,滾動和縮放工作。然而,當我放大mapview(大約5-10倍),然後再縮小到第一個尺寸,一些註釋位置被改變(見底部註釋)。 我不會在這裏發佈函數viewForAnnotation,因爲它沒有被調用,我只是放大/縮小它發生的事情。 http://cC8.upanh.com/27.800.35078007.mF80/1.pnghttp://cC9.upanh.com/27.800.35078008.AWG0/2.png

+0

你確定viewForAnnotation:永遠不會被調用嗎?我認爲這可能是由重用annotationView引起的。 – ender

+0

哦,你是對的。我再次查看viewForAnnotation函數後解決了問題。這裏是我的舊代碼: – toandk

+0

也許你應該更新你的問題,並顯示你是如何修復它 – ender

回答

1

哦,你說得對。我再次查看viewForAnnotation函數後解決了問題。在我的舊代碼中,當調用[mapView dequeueReusableAnnotationViewWithIdentifier:identifier]時,我只爲所有註釋設置標識符爲「Image」。它使得這個函數每次都得到一個隨機的註解。通過指定每個註釋的真實標識符來解決。感謝您的警告!