MKMapKit exception when using canShowCallout on annotation view

Posted by Kendall Helmstetter Gelner on Stack Overflow See other posts from Stack Overflow or by Kendall Helmstetter Gelner
Published on 2010-03-04T08:37:22Z Indexed on 2010/05/18 9:40 UTC
Read the original article Hit count: 298

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about mkmapview