MKMapKit exception when using canShowCallout on annotation view
- by Kendall Helmstetter Gelner
I'm trying to use a pretty straightforward custom map annotation view and callout - the annotation view when I create it, just adds a UIImageView as a subview to itself. That works fine.
However, when I call canShowCallout on the annotation view, An exception is thrown in MapKit immediately after returning the view. The end of the stack looks like:
#0 0x94e964e6 in objc_exception_throw
#1 0x01e26404 in -[MKOverlayView _addViewForAnnotation:]
#2 0x01e22037 in -[MKOverlayView _addViewsForAnnotations:animated:]
#3 0x01e1ddf9 in -[MKOverlayView showAddedAnnotationsAnimated:]
#4 0x01df9c0e in -[MKMapView _showAddedAnnotationsAndRouteAnimated:]
#5 0x01e0371a in -[MKMapView levelView:didLoadTile:]
My viewForAnnotation is pretty simple:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
if ( ! [annotation isKindOfClass:[MyAnnotation class]] )
return nil;
MyAnnotationView *useView = (MyAnnotationView *)[myMapView dequeueReusableAnnotationViewWithIdentifier:@"resuseview"];
if ( useView == nil )
{
useView = [[[MyAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"resuseview"] autorelease];
useView.canShowCallout = YES; // if commented out view appears just fine
}
else
{ useView.annotation = annotation; }
return useView;
}
As noted in the code, the annotation view works fine as is - until I add canShowCallout, then it crashes the first time the map gets the view.