-1

I have an app that calls addAnnotation exactly 3 times (after verifying that the coordinates are good using CLLocationCoordinate2DIsValid, passing a model that responds to id, title latitude, longitude and coordinate. In the model, I watch the callbacks by doing an NSLog in my coordinate method.

Note that coordinate and name are implemented as methods, although this should make no difference, right?

What I expect:

MapKit will access the coordinate method 3 times

What I get:

MapKit access the coordinate 3 times per coordinate, then tries a 4th time, even though there is no 4th coordinate and the app crashes on a memory exception as the result is nil.

I am pretty naive about MapKit, but there has to be some explanation for this that I'm missing.

Any help appreciated!

Steve Ross
  • 4,134
  • 1
  • 28
  • 40

1 Answers1

1

If the user location is shown on your map (the blue dot) you'll have four annotations, as the blue dot also is an annotation.

Your app probably crashes as the annotation used to show the user location has no method called coordinate

To prevent your code to call the method coordinate you can either check if the retrieved annotation is an instance of your custom annotation class:

if ([annotion isKindOfClass:[YourCustomeAnnotation class]])
    // it's one of your annotations
else
    // it's the current location annotation 

or check if the current annotation is the current location anotation

if ([annotion isKindOfClass:[MKUserLocation class]])
    // it's the current location annotation 
else
    // it's one of your annotations
pre
  • 3,475
  • 2
  • 28
  • 43
  • How do I detect this and make the model not respond to it? I'm sorry not to have provided sample code, but it's in RubyMotion and I'm almost ready to rewrite it in Objective-C to see if I can repro it that way. – Steve Ross Jun 04 '13 at 19:55