我已經看過其他報告,似乎沒有適用。我們的應用程序正在被削弱頻繁(但並不可靠重複性)崩潰這樣的:在MKMapView annotationContainer中持續崩潰:viewForAnnotation
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x333a6c98 objc_msgSend + 16
1 MapKit 0x30be52fc -[MKMapView annotationContainer:viewForAnnotation:] + 36
2 MapKit 0x30be4f8e -[MKAnnotationContainerView _addViewForAnnotation:] + 270
3 MapKit 0x30c0f164 -[MKAnnotationContainerView addViewForManagedAnnotation:notifyDelegate:] + 12
4 MapKit 0x30c0b874 -[MKMapView(UserPositioningInternal) _runPositioningChange] + 1036
5 MapKit 0x30c09a86 -[MKMapView(UserPositioningInternal) _startPositioningChange:] + 22
6 MapKit 0x30c0d04a -[MKMapView(UserPositioningInternal) locationManagerUpdatedLocation:] + 578
7 CoreFoundation 0x360bcefc -[NSObject(NSObject) performSelector:withObject:] + 16
8 CoreFoundation 0x360fa2f2 -[NSArray makeObjectsPerformSelector:withObject:] + 394
9 MapKit 0x30bfc802 -[MKLocationManager _reportLocationStatus:] + 34
10 MapKit 0x30bfdd6c -[MKLocationManager _reportLocationSuccess] + 36
11 MapKit 0x30bfd9c6 -[MKLocationManager locationManager:didUpdateToLocation:fromLocation:] + 674
的這個報告帶來很多在網絡上,但很多似乎去解決。我沒有做任何瘋狂的事情,只是在地圖上顯示用戶的位置和一個標記。我跟着我可以找到的例子,我已經看過代碼,但找不到任何代碼。
這裏是我的MapView代表如何處理viewForAnnotation:
- (MKAnnotationView*)mapView:(MKMapView*)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
// If it's the user location, just return nil.
if([annotation isKindOfClass:[MKUserLocation class]])
{
return nil; // Use default system user-location view.
}
else
{
// Try to dequeue an existing pin view first.
MKPinAnnotationView* pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:@"stashMarkerID"];
if(!pinView)
{
// If an existing pin view was not available, create one.
pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:@"stashMarkerID"] autorelease];
pinView.pinColor = MKPinAnnotationColorPurple;
pinView.animatesDrop = YES;
pinView.canShowCallout = NO;
}
else
{
pinView.annotation = annotation;
}
return pinView;
}
}
崩潰,似乎與用戶的位置的變化有關,但一旦用戶位置標記添加的,我不惹它。當我需要刷新另一個地圖標記,我刪除了另一個時跳過用戶標記:
// Add the marker to the map.
// Remove old one(s) first.
int i = 0;
while(i < [mapView.annotations count])
{
if ([[mapView.annotations objectAtIndex:i] isKindOfClass:[StashMarker class]])
{
[mapView removeAnnotation:[mapView.annotations objectAtIndex:i]];
}
else
{
i++;
}
}
的代表是整個屏幕控制器,所以它沒有被釋放;在屏幕啓動時發生崩潰。這不是問題,但地圖顯示的信息如下:
任何猜測或洞察力將不勝感激!這是在iOS 5.0.1上。
更新:我們發現,當沒有MKMapView甚至存在時,發生這種崩潰。包含它的視圖早已被彈出。我在想,如果我們遇到此報告的問題:MKMapView crashes app when view controller popped
更新2:這裏有一個本質上是一回事另一份報告:Why am I crashing after MKMapView is freed if I'm no longer using it?
這似乎可可異常凌亂,具有的MKMapView的委託後設置爲零我們期望MapView被釋放。按照這個速度,爲什麼我們不需要爲接受委託的所有控制執行此操作?
在未來的問題中,請不要發佈代碼和日誌的截圖。相反,請複製並粘貼文字。 – Anna
你在使用CLLocationManager嗎?刪除註釋的代碼是什麼方法(我會採用不同的方式)?該代碼之前或之後做了什麼?你在didUpdateUserLocation或didUpdateToLocation委託方法中有什麼代碼? – Anna
你將如何刪除註釋不同? – Oscar