Friday, 28 October 2016

Image background service

NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"image url"]];

    cell.image = [UIImage imageWithData: imageData];

change to

dispatch_async(dispatch_get_global_queue(0,0), ^{
        NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"image url"]];
        if ( data == nil )
            return;
        dispatch_async(dispatch_get_main_queue(), ^{
            // WARNING: is the cell still using the same data by this point??
            cell.image = [UIImage imageWithData: data];
        });
    });

No comments:

Post a Comment