iOS11 Beta MKAnnotationView hidden by mistake

We are seeing a new problem on iOS11 with some of our MKAnnotationViews not showing. They are all working fine on iOS10. Some display fine on iOS11 others don't. When we print information about the non-diplaying MKAnnotationView in the debugger we see:-


<MyAnnotationView: 0x10ab2ffc0; frame = (68.0071 237.374; 253.07 70.253); hidden = YES; layer = <_MKAnnotationViewLayer: 0x1c0a27f20>>


However we cannot change the hidden attribute. e.g. [myAnnotationView setHidden:NO] has no effect.


In the Debug View Hierarchy we can see that myAnnotationView has been added to the map but is hidden ( disabled “Show only displayed views”).


We have found a workaround driven by a clue whilst debugging. If we breakpoint just before the MyAnnotationView is returned to MKMapKit in


- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation


and eyeball (Quick look) the view in the debugger just before it is returned to the MkMapView, it is visible in the preview pane and if we then dump (print the variable) the Hidden attribute has now mysteriously disappeared and on resuming the run the annotationView now displays on the map!


<MyAnnotationView: 0x10ab2ffc0; frame = (68.0071 237.374; 253.07 70.253); layer = <_MKAnnotationViewLayer: 0x1c0a27f20>>


So we mimicked this in code by drawing the myAnnotationView to a graphics context and getting the image from it.


CGContextRef ctx = UIGraphicsGetCurrentContext();

[self.layer renderInContext:ctx];

UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext()

and now myAnnotationView displays fine all the time. We would prefer a fix rather than a workaround. Anyone else experienced this and got a clue what is wrong?

Replies

I am having the same problem, my custom annotation views are not being displayed in the beta. In the method


- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation


just before the view is returned, I tried the new prepareForDisplay method on the view. I can't find any documentation on this method, but apparently it showed up in beta 4. Running this method makes the view not hidden, but it is still displayed behind other annotations...

I have this same issue with the custom MKAnnotationViews not showing on the MKMapView. Have you raised this via the bug reporter so that I can clone it and let Apple know that multiple people are seeing this? If so, can you post the bug id please?


Thanks

I'm seeing the same issue, but only on macOS (and then, only when displaying a MKMapView inside a modal window; my App's main window also contains a MKMapView and there's no problem with the annotations displayed on this main MKMapView, even though they are exactly the same MKAnnotation subclass).


I also have multiple Apps running on iOS which don't exhibit this problem, so I think it must be quite an obscure combination of factors which cause it. But when your App suffers this problem, it seems that it's not at all easy to get rid of it. I've tried all the usual workarounds, but there seems no way to change the AnnotationView's .isHidden property once it's been set by the constructor. I tried reverting to a vanilla MKAnnotationView, but this also has .isHidden set to true. So I'd presume this is a "mode" that MKMapKit gets into, perhaps based on a selection of the configuration properties (??).


I'll add a bug report, but I don't hold out much hope of a quick fix, given how slowly MapKit bugs seem to be addressed lately.