美文网首页
异步加载图片

异步加载图片

作者: 黑夜的眼睛 | 来源:发表于2016-01-21 18:10 被阅读17次

    cell.imgView.image= [UIImageimageNamed:@""];

    NSString*url = dic[@"snapshot_url"];

    if(url) {

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{

    NSURLRequest*request = [NSURLRequestrequestWithURL:[NSURLURLWithString:url]];

    NSData*data = [NSURLConnectionsendSynchronousRequest:requestreturningResponse:nilerror:nil];

    dispatch_async(dispatch_get_main_queue(), ^{

    if(data) {

    cell.imgView.image= [UIImageimageWithData:data];

    [cellsetNeedsDisplay];

    }

    });

    });

    }

    相关文章

      网友评论

          本文标题:异步加载图片

          本文链接:https://www.haomeiwen.com/subject/oxwlkttx.html