gpt4 book ai didi

ios - MKmapView.overlays 返回 nil - 崩溃

转载 作者:行者123 更新时间:2023-11-28 09:24:17 25 4
gpt4 key购买 nike

Self.mapView.overlays 返回 nil 而不是 [],

这会导致崩溃。

崩溃函数:

fileprivate func addRadiusToUserLocation(userCoordinate: CLLocationCoordinate2D,radius : Double) {
let radiusCircle = MKCircle(center: userCoordinate, radius: radius)
self.mapView.removeOverlays(self.mapView.overlays)
self.mapView.addOverlays([radiusCircle])
}

堆栈:

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)

addRadiusToUserLocation 调用:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

map View :

@IBOutlet var mapView: MKMapView!

谢谢。

最佳答案

它看起来像线程问题。

我能够通过将 addoverlay 和 removeoverlay 移动到主线程来修复它。

fileprivate func addRadiusToUserLocation(userCoordinate: 
DispatchQueue.main.async {
CLLocationCoordinate2D,radius : Double) {
let radiusCircle = MKCircle(center: userCoordinate, radius: radius)
self.mapView.removeOverlays(self.mapView.overlays)
self.mapView.addOverlays([radiusCircle])
}

关于ios - MKmapView.overlays 返回 nil - 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47494524/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com