Self.mapView.overlays返回nil而不是[],
这导致了崩溃。
崩溃功能:
td
堆栈:
fileprivate func addRadiusToUserLocation(userCoordinate: CLLocationCoordinate2D,radius : Double) {
let radiusCircle = MKCircle(center: userCoordinate, radius: radius)
self.mapView.removeOverlays(self.mapView.overlays)
self.mapView.addOverlays([radiusCircle])
}
addRadiusToUserLocation调用:
Fatal Exception: NSInvalidArgumentException
*** -[__NSSetM removeObject:]: object cannot be nil
0 CoreFoundation 0x18307bd38 __exceptionPreprocess
1 libobjc.A.dylib 0x182590528 objc_exception_throw
2 CoreFoundation 0x183014c44 _CFArgv
3 CoreFoundation 0x182f46264 -[__NSCFString hash]
4 VectorKit 0x193139ca8 -[VKRasterOverlayTileSource removeOverlay:]
5 VectorKit 0x192dc74b8 -[VKMapModel removeRasterOverlay:]
6 MapKit 0x19342b7f0 -[MKOverlayContainerView _removeDrawable:forOverlay:level:]
7 MapKit 0x19342acd0 -[MKOverlayContainerView removeOverlay:]
8 MapKit 0x19342adc8 -[MKOverlayContainerView removeOverlays:]
9 0x10429bfd8 SiteMapManager.addRadiusToUserLocation(userCoordinate:radius:) (SiteMapManager.swift:156)
10 0x10429d184 specialized SiteMapManager.addOrUpdateUserLocation(userLocation:radius:) (SiteMapManager.swift:48)
11 0x10429f1cc specialized SiteMapManager.mapView(_:viewFor:) (SiteMapManager.swift:203)
12 0x10429c164 @objc SiteMapManager.mapView(_:viewFor:) (SiteMapManager.swift)
13 MapKit 0x1933e99e8 -[MKMapView annotationManager:representationForAnnotation:]
14 MapKit 0x1933a7ba4 -[MKAnnotationManager _addRepresentationForAnnotation:]
15 MapKit 0x1933a68f0 -[MKAnnotationManager updateVisibleAnnotations]
16 MapKit 0x1933c1620 -[MKMapView _didChangeRegionMidstream:]
17 MapKit 0x1933dddf0 -[MKMapView mapLayer:didChangeRegionAnimated:]
18 VectorKit 0x192d90690 -[VKMapView map:didChangeRegionAnimated:]
19 VectorKit 0x192d3fc74 -[VKMapCameraController rotateToYaw:withPoint:animated:]
20 VectorKit 0x192df7d84 -[VKMapCameraController snapMapIfNecessary:]
21 MapKit 0x19342b7f0 -[MKOverlayContainerView _removeDrawable:forOverlay:level:]
22 MapKit 0x19342acd0 -[MKOverlayContainerView removeOverlay:]
23 MapKit 0x19342adc8 -[MKOverlayContainerView removeOverlays:]
24 0x10429bfd8 SiteMapManager.addRadiusToUserLocation(userCoordinate:radius:) (SiteMapManager.swift:156)
MapView的:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
谢谢你。
答案 0 :(得分:0)
它看起来像是一个线程问题。
我能够通过将addoverlay和removeoverlay移至主线程来对其进行修复。
id,groupId,vehicleId,currentVehicleId,username,name
134763,1234,212014918234742,212014918234742,ablah,Art Blah
134764,1234,212014918234709,212014918234709,btodd,Barry Todd
}
答案 1 :(得分:-1)
在删除之前,您需要检查mapview叠加层是否为nil
fileprivate func addRadiusToUserLocation(userCoordinate: CLLocationCoordinate2D,radius : Double) {
let radiusCircle = MKCircle(center: userCoordinate, radius: radius)
if(self.mapView.overlays != nil){
self.mapView.removeOverlays(self.mapView.overlays)
}
self.mapView.addOverlays([radiusCircle])
}