altering the mkmapview (removing annotations)

ⅰ亾dé卋堺 提交于 2019-12-08 03:56:34

问题


I have a weird crash occurred in my application First of all, I would get you a glance about the application, there is a map that contains many annotations and also I customized the callout of these annotation to be a view that contains buttons and many information, it contains a button that have an action to go to another tab in the application, it is called DisclosureButton

I added a breakpoint exception to the project so I got where the app is crashed, you can see it above at line 173 As you can see in the above console, the view.annotation is null so the annotations was removed at some point. After checking the action performed by thread 1(the main thread, you can see it below) I see that while removing the annotations from the map, the disclosure button action is performed. why the main thread stops to the perform the updateMap method and start the action for the disclosure button? that’s what the console shows first “before remove the annotation” then the logs within the action of the disclosureButton without logging “before creation the annotation”, it is something very weird, I’m not sure what is happening at this point ???

I'm not sure what is happening, any suggestion/comments/assistance would be appreciated

Thanks in advance,


回答1:


iOS 6 likes to blast the annotations in the map, for who knows why. My solution is to just retain the annotation (s) in the owning class, and handle the memory. It's working for now, but it doesn't let the native mapKit handle it... unsure if there's a new WWDC video I should watch or a page added to MKMap programming documents, but for now this works.




回答2:


I think I had the same problem. My background thread was adding/removing the annotations but the button on an annotation will be added in the main thread. This also means that the main thread does an enumeration on the annotations (for some reason). I fixed it by doing the adding in the main thread.

Problem exists only on iOS 6.

I'm not sure what your exception was but mine was:

* Collection <__NSArrayM: 0x136d57c0> was mutated while being enumerated.

0   CoreFoundation                      0x0330e02e __exceptionPreprocess + 206
1   libobjc.A.dylib                     0x02735e7e objc_exception_throw + 44
2   CoreFoundation                      0x03396cc5 __NSFastEnumerationMutationHandler + 165
3   MapKit                              0x0231748c -[MKAnnotationContainerView _updateAnnotationViewPerspective] + 399
4   MapKit                              0x02305520 -[MKMapView _updateScrollContainerView:] + 2478
5   MapKit                              0x02303e10 -[MKMapView _didChangeRegionMidstream:] + 97
6   MapKit                              0x02305d66 -[MKMapView _goToMapRegion:duration:animationType:] + 828
7   MapKit                              0x023061bd -[MKMapView _setZoomScale:centerMapPoint:duration:animationType:] + 711
8   MapKit                              0x02305a24 -[MKMapView _setZoomScale:centerCoordinate:duration:animationType:] + 121
9   MapKit                              0x02307f8f -[MKMapView _goToCenterCoordinate:zoomLevel:animationType:cancelDefaultLocationTimer:] + 950
10  MapKit                              0x023075fb -[MKMapView goToCenterCoordinate:zoomLevel:animationType:] + 81
11  MapKit                              0x023076c9 -[MKMapView goToCenterCoordinate:longLatSpan:animationType:] + 178
12  MapKit                              0x0230992a -[MKMapView goToDefaultLocation] + 415
13  Foundation                          0x009a0b90 __NSFireTimer + 97
14  CoreFoundation                      0x032cd376 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
15  CoreFoundation                      0x032cce06 __CFRunLoopDoTimer + 534
16  CoreFoundation                      0x032b4a82 __CFRunLoopRun + 1810
17  CoreFoundation                      0x032b3f44 CFRunLoopRunSpecific + 276
18  CoreFoundation                      0x032b3e1b CFRunLoopRunInMode + 123
19  GraphicsServices                    0x03c557e3 GSEventRunModal + 88
20  GraphicsServices                    0x03c55668 GSEventRun + 104
21  UIKit                               0x00d3465c UIApplicationMain + 1211
22  myApp                               0x00002c93 myApp + 7315
23  myApp                               0x00002bd5 myApp + 7125


来源:https://stackoverflow.com/questions/12205051/altering-the-mkmapview-removing-annotations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!