• GCD多线程 在子线程中获取网络图片 在主线程更新


    子线程中得所有数据都可以直接拿到主线程中使用
    //当触摸屏幕的时候,从网络上下载一张图片到控制器的view上显示
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        
         //获取一个全局并行队列
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
         //把任务添加到队列中执行
         dispatch_async(queue, ^{
             //打印当前线程
             NSLog(@"%@",[NSThread currentThread]);
           //从网络上下载图片
             NSURL *urlstr=[NSURL URLWithString:@"http://h.hiphotos.baidu.com/baike/w%3D268/sign=30b3fb747b310a55c424d9f28f444387/1e30e924b899a9018b8d3ab11f950a7b0308f5f9.jpg"];
             NSData *data=[NSData dataWithContentsOfURL:urlstr];
    UIImage *image=[UIImage imageWithData:data]; //提示 NSLog(@"图片加载完毕"); dispatch_async(dispatch_get_main_queue(), ^{ self.imageView.image=image; //打印当前线程 NSLog(@"%@",[NSThread currentThread]); }); }); }
     
  • 相关阅读:
    Scala 并发编程
    rsyslog start with
    rsyslog start with
    logrotate 日志清理后 rsyslog中断问题
    logrotate 日志清理后 rsyslog中断问题
    logrotate 清理tomcat日志
    rsyslog 传输mysql 日志
    rsyslog 传输mysql 日志
    NYOJ833
    NYOJ65
  • 原文地址:https://www.cnblogs.com/zeroChan/p/4968915.html
Copyright © 2020-2023  润新知