Terrabythia
Terrabythia

Reputation: 2141

iPhone objective c: unrecognized selector sent to instance AsyncImageLoader

I'm using this AsyncImageLoader to load images asynchronously: AsyncImageView.

When I try to load an image resource whit the method loadImageWithURL, I keep getting the error: unrecognized selector sent to instance.

The class (AsyncImageLoader) is trying to perform the selector like this:

[target performSelectorOnMainThread:success withObject:image waitUntilDone:NO];

My code is like this:

-(void)thumbImageLoadSucces:(id)sender {

    NSLog(@"imageloadedsucces");

}

-(void)thumbImageLoadError:(id)sender {

    NSLog(@"imageloadederror");

}

And then somewhere else in the same Controller:

[self.asyncImageLoader loadImageWithURL:url target:self.thumb success:@selector(thumbImageLoadSucces:) failure:@selector(thumbImageLoadError:)];

Can anybody tell me why I keep getting this error? I've tried the other solutions given to this error here on SO, but nothing helped (it was mostly a typo in the code, but I checked my code for errors).

Upvotes: 0

Views: 760

Answers (3)

Midhun MP
Midhun MP

Reputation: 107141

Here is the issue:

[target performSelectorOnMainThread:success withObject:image waitUntilDone:NO];

You forgot to add the selector. You need to write like:

[target performSelectorOnMainThread:@selector(thumbImageLoadSucces:) withObject:image waitUntilDone:NO];

Upvotes: 0

Ramaraj T
Ramaraj T

Reputation: 5230

I think you problem is with your target location Try changing this

[self.asyncImageLoader loadImageWithURL:url target:self.thumb success:@selector(thumbImageLoadSucces:) failure:@selector(thumbImageLoadError:)];

into

[self.asyncImageLoader loadImageWithURL:url target:self success:@selector(thumbImageLoadSucces:) failure:@selector(thumbImageLoadError:)];

i.e. self.thumb into self

Upvotes: 1

mattjgalloway
mattjgalloway

Reputation: 34912

Presumably you have your target wrong. It needs to be:

[self.asyncImageLoader loadImageWithURL:url target:self success:@selector(thumbImageLoadSucces:) failure:@selector(thumbImageLoadError:)];

The async loader is going to perform those selectors on the target. So it's the target that needs to respond to them. Then in the success & failure methods you'll set the image on the image view.

Upvotes: 2

Related Questions