Question

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.

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top