[UIImageView _isResizable]: unrecognized selector sent to instance SIGABRT

Luke picture Luke · Mar 7, 2012 · Viewed 12.5k times · Source

I've got this code trying to run a simple set of images in a cycle. All I have in the app is one UIImageView declared in my View Controller's .h file:

@property (strong, nonatomic) IBOutlet UIImageView *imageDisplay;

And the following in my .m file's viewDidLoad method:

NSMutableArray *imageView = [[NSMutableArray alloc] init];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim1.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim2.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim3.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim4.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim5.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim6.png"]]];
[imageView addObject:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"EyeAnim7.png"]]];

imageDisplay.animationImages = imageView;
imageDisplay.animationDuration = 0.25;
imageDisplay.animationRepeatCount = 50;
[imageDisplay startAnimating];

The code seems to be crashing on the "imageDisplay.animationImages" line, as if I create the UIImageView, create its getter and setter, and build, it's fine until I uncomment that line. If I do uncomment it, it keeps giving me the error until I delete the UIImageView and create a new one.

Not too sure what's happening, any help appreciated!

Answer

David Collingwood picture David Collingwood · Jun 8, 2013

I am very new to objective-c and I have been getting this error also, but for a different reason. I just wanted to post my solution for anyone else who may be struggling.

So basically I have a custom class called ImagesDetailViewController which inherits from UIViewController and has an image property.

@interface ImagesDetailViewController : UIViewController
@property (strong, nonatomic) UIImage *image;
@end

I then connected my class to my UIImageView on my storyboard like so

@interface ImagesDetailViewController ()
@property (nonatomic, weak) IBOutlet UIImageView *imageView;
@end

In my viewDidLoad method I was trying to set the image for my image view like this and getting the error mentioned above (my image variable gets initialised in a prepareForSegue method)

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.imageView setImage:self.image];
}

So I was stumped as I bet you are all too. The problem had to do with the storyboard. Clicking on my UIImageView and then navigating to the Connections Inspector, I had somehow created 2 referencing outlets (oops...) and one was pointing to a variable called image. So when the program was running [self.imageView setImage:self.image] self.image was actually an instance of UIImageView instead of UIImage.