Note that there are some explanatory texts on larger screens.

plurals
  1. POMKUserLocation blue userLocation MKAnnotation causes app to crash if inadvertently touched
    text
    copied!<p>I have a <code>MKMap</code> with a series of <code>MKAnnotations</code>, all of which are red which is fine. I have selected "show user location" in IB and to change the <code>MKAnnotation</code> from red to blue, I have the code in my <code>viewForAnnotation</code> method: </p> <pre><code>if (annotation == theMap.userLocation) return nil; </code></pre> <p>All is good and the app works fine, but if the user inadvertently taps the blue userlocation dot I get the following crash:</p> <pre><code>2012-02-01 20:43:47.527 AusReefNSW[27178:11603] -[MKUserLocationView setPinColor:]: unrecognized selector sent to instance 0x79b0720 2012-02-01 20:43:47.528 AusReefNSW[27178:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MKUserLocationView setPinColor:]: unrecognized selector sent to instance 0x79b0720' *** First throw call stack: </code></pre> <p>If I remove the above code, all works well but the pin is red. I perfer to have the blue icon but as yet have not discovered why the crash. Any ideas would be appreciated. Thanks.</p> <p>SOLVED! Thanks Marvin and heres the code incase anyone finds it useful. In a nutshell, I had to first check to see if the MKAnnotation was of MyAnnotation Class or of MKUserLocation Class.</p> <pre><code>- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKPinAnnotationView *)view { theAnnotationSelected = [[mapView selectedAnnotations] objectAtIndex:0]; if ([theAnnotationSelected isKindOfClass:[MyAnnotation class]] ) { view.pinColor = MKPinAnnotationColorGreen; } - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKPinAnnotationView *)view { if ([theAnnotationSelected isKindOfClass:[MyAnnotation class]] ) { view.pinColor = MKPinAnnotationColorRed; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload