performSelectorInBackground: using self.object ?
- by Emil
Hey. I am trying to load an image for a custom tableViewCell. The code gets run from the CustomCell-class (CustomCell.h) from [cell performSelectorInBackground:@selector(loadImageFromURL:) withObject:[NSURL URLWithString:urlString]]; in the cellForRowAtIndexPath:-function.
Cell gets created here:
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[CustomCell class]]){
cell = (CustomCell *) currentObject;
break;
}
}
}
CustomCell.h:
// ...
IBOutlet UIImageView *cellImage;
}
- (void) loadImageFromURL:(NSURL *)url;
// …
CustomCell.m:
- (void) loadImageFromURL:(NSURL *)url {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Loading image...");
[loadingImage startAnimating];
[self.cellImage setImageWithURL:url];
[loadingImage stopAnimating];
NSLog(@"Done loading image...");
[pool release];
}
setImageWithURL: is a function from the SDWebImage-framework that rs has made.
The real error is that the image doesen't show up.
EDIT: When I cleared the app's cache, the images didn't show up anymore.
EDIT: Seems like URL is nil for some reason. Am I passing the object in the selector correctly?
Can you see anything wrong?
Thanks.