0

I seem to be having a little trouble getting the route-me markers to hide. They seem to show fine but if I try to hide them with a for loop it seems to crash. Here is what I have:

- (void) tapOnMarker: (RMMarker*) marker onMap: (RMMapView*) map{
   NSArray* markers = mapView.markerManager.markers;
   for(RMMarker *mk in markers) {
       [mk hideLabel];
   }
   [marker showLabel];
}

The for loop in theory should loop through all the markers that are in the marker manager and hide them, but instead it crashes out with this error message:

-[RMMapLayer hideLabel]: unrecognized selector sent to instance 0x83f7680
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RMMapLayer hideLabel]: unrecognized selector sent to instance 0x83f7680'
*** First throw call stack:
(0x1b91012 0x1959e7e 0x1c1c4bd 0x1b80bbc 0x1b8094e 0x4afa 0x6978a 0x8d433f 0x8d4552 0x8b23aa 0x8a3cf8 0x256bdf9 0x256bad0 0x1b06bf5 0x1b06962 0x1b37bb6 0x1b36f44 0x1b36e1b 0x256a7e3 0x256a668 0x8a165c 0x2b75 0x2a75)
libc++abi.dylib: terminate called throwing an exception

Looking at this error message closely I do notice something, Why is it calling RMMapLayer? the hideLabel function is in RMMarker class. I do specifically write it as "RMMarker *mk in markers". What am I doing wrong here? Thanks ahead for any help you can offer.

Ray Y
  • 1,261
  • 3
  • 16
  • 24
  • It's happening because RMMarker inherits from RMMapLayer. You'll need to do some introspection on the mk object to ensure you have the correct class of object. My guess is that there are other objects in the markers array of different types than just RMMarker.... – HackyStack Nov 12 '12 at 20:37

1 Answers1

1

Try something like this in your for loop:

 if ([mk isKindOfClass:[RMMarker class]])
    [mk hideLabel];
 else
    NSLog(@"We have a different class here:  %@", [mk class]);

You could also use the "respondsToSelector" method to prevent it...

HackyStack
  • 4,887
  • 3
  • 22
  • 28
  • You are correct, There are other objects in the array than just RMMarkers, I just assumed that there were only markers in the array. This works great now. Thanks for all your help. – Ray Y Nov 12 '12 at 20:49