• GCD使用三 -- 线程间通信


    #define HMGlobalQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
    #define HMMainQueue dispatch_get_main_queue()

    dispatch_async(HMGlobalQueue, ^{
    NSLog(@"donwload---%@", [NSThread currentThread]);
    // 1.子线程下载图片
    NSURL *url = [NSURL URLWithString:@"http://d.hiphotos.baidu.com/image/pic/item/37d3d539b6003af3290eaf5d362ac65c1038b652.jpg"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    UIImage *image = [UIImage imageWithData:data];

    // 2.回到主线程设置图片
    dispatch_async(HMMainQueue, ^{
    NSLog(@"setting---%@ %@", [NSThread currentThread], image);
    [self.button setImage:image forState:UIControlStateNormal];
    });
    });

  • 相关阅读:
    二分
    枚举
    dp
    bfs
    bfs
    dfs
    ipython快捷键
    虚拟机串口连接嵌入式开发板
    rtmp向IR601移植过程(无功能步骤,只有移植步骤)
    静态库和动态库
  • 原文地址:https://www.cnblogs.com/fangchun/p/4691291.html
Copyright © 2020-2023  润新知