Search code examples
objective-ciosunrecognized-selectorcs193p

Why am I getting a unrecognized selector sent to instance exception with my MapViewController? (iOS)


I'm taking the Stanford iOS class (sorry, I'm one of these guys but gotta learn somehow I guess) and I'm using code that is almost exactly the same as the code that the prof used in the lecture about MKMapViews but I'm getting this exception that he didn't and I really can't figure it out. What could be causing this?

The exception I'm getting:

-[NSConcreteData _isResizable]: unrecognized selector sent to instance 0x90a4c00

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapVC"];
    if (!aView) {
        aView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:@"MapVC"];
        aView.canShowCallout=YES;
        aView.leftCalloutAccessoryView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
        aView.rightCalloutAccessoryView= [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    }
    aView.annotation=annotation;
    [(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
    return aView;
}

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    UIImage *image = [self.delegate getImageForMapViewController:self withAnnotation:view.annotation];
    [(UIImageView *)view.leftCalloutAccessoryView setImage:image]; // this is where I get the exception.
}

Solution

  • The error -[NSConcreteData _isResizable]: unrecognized selector sent to instance can happen when calling setImage on a UIImageView if the parameter you are passing is not really a UIImage.

    According to your comment, the getImageForMapViewController method is actually returning NSData instead of a UIImage. This can cause the error you are seeing.

    Fix the getImageForMapViewController method to return a UIImage.