Wednesday, 14 May 2014

Assign placeholder image in tableview Cell(Load image asynchrous)

if u Load original image from server,it will take time at that time we show a another image still that original image loaded:


NSURL *imageURL = [NSURL URLWithString:Details.imageUrl];
    cell.imageView.image=[UIImage imageNamed:@"flower.png"];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSData *data = [NSData dataWithContentsOfURL:imageURL];
        
        if (data) {
            UIImage *offersImage = [UIImage imageWithData:data];
            if (offersImage) {
                dispatch_async(dispatch_get_main_queue(), ^{
                    UITableViewCell *updateCell = [tableView cellForRowAtIndexPath:indexPath];
                    
                    if (updateCell) {
                        updateCell.imageView.image = offersImage;
                    }
                });
            }
        }

    });

No comments:

Post a Comment