我有一些問題的MKMapView /註釋/ UINavigationController的。基本上,我使用UINavigationController管理我的視圖;我的一個視圖包含一個MKMapView,並使用addAnnotations方法在其上添加註釋(10到200)。addAnnotations問題(內存管理也許?)
一切工作,除了一件事罰款:如果我定位我的UINavigationController「太快」,iPhone模擬器死機,接收「EXC錯誤訪問」的信號。例如,如果我加載包含MKMapView的視圖並立即按下UINavigationController導航欄中的「返回」按鈕,我就會得到信號。我認爲問題出在addAnnotations方法上:當我的MKMapView被加載時,我給它添加了註釋,但它看起來像所有事情都是異步完成的。如果我在按「返回」按鈕之前等待一秒鐘,我不會出錯,但如果我速度太快,就會崩潰。如果我刪除addAnnotations行,則完全沒有錯誤。我想這是因爲我的視圖是在添加註釋方法完成工作之前由UINavigationController發佈的。
任何這個好的解決方案?我不希望用戶等待(例如顯示加載視圖);我想解決方案可能是一個更好的內存管理,但我不明白我能做到這一點。
if(DEBUG_MODE) { NSLog(@"Creating array of placemarks : begin"); }
self.placemarkCache = [[NSMutableArray alloc] init];
// Loading placemarks for a placemark dictionary
NSArray *sortedKeys = [[self.placemarkDictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];
for (id key in sortedKeys) {
MyPlacemark *currentPlacemark = [self.placemarkDictionary objectForKey:key];
[self.placemarkCache addObject:currentPlacemark];
[currentPlacemark release];
}
if(DEBUG_MODE) { NSLog(@"Creating array of placemarks : done"); }
if(DEBUG_MODE) { NSLog(@"Adding placemarks : begin"); }
[self.mapView addAnnotations:self.placemarkCache];
if(DEBUG_MODE) { NSLog(@"Adding placemarks : done"); }
在這個例子中,在地圖上顯示任何東西之前,我會看到「添加地標:完成」消息。
這是完全相同的問題,它的工作:) 現在聽起來很明顯... 感謝您的回答! – Vivi 2009-09-07 16:41:39
您的鏈接不再有效。 – J2theC 2013-06-07 20:28:57