performSelectorInBackground: using self.object ?

Posted by Emil on Stack Overflow See other posts from Stack Overflow or by Emil
Published on 2010-06-18T11:44:11Z Indexed on 2010/06/18 11:53 UTC
Read the original article Hit count: 365

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uitableviewcell