zoukankan      html  css  js  c++  java
  • GET异步 请求图片步骤

    - (IBAction)getImage:(id)sender {

        //1,准备URL

        NSString *str = @"http://e.hiphotos.baidu.com/image/h%3D1200%3Bcrop%3D0%2C0%2C1920%2C1200/sign=e13d66699825bc31345d059a6eefb6d2/6159252dd42a2834f85385ac5ab5c9ea14cebfa4.jpg";

        

        NSURL *url = [NSURL URLWithString:str];

        

        //2,创建请求对象

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        

        //链接对象,block 异步

        __block MXTViewController *weakSelf = self;

        NSOperationQueue *queue = [[NSOperationQueue new] autorelease];

        [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

            //获取data

            UIImage *image = [UIImage imageWithData:data];

            

            //回到主线程更新页面

            dispatch_sync( dispatch_get_main_queue(), ^{

                //block 不可以使用_imageView 的方式访问属性,会造成self 引用计数+1 ,不能使用强引用

                //要使用weak

                weakSelf.imageView.image = image;

            });

        }];

        

  • 相关阅读:
    TPLINK TLWR710N设置详解
    hehe.....
    AS3写FTP登录过程
    QQ
    网页设计标准尺寸:
    女孩,你愿意做他的第几个女朋友
    監聽一個變量的值變化
    dispatchEvent
    10
    C#常用代码
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/4177612.html
Copyright © 2011-2022 走看看