线程7--GCD的基本使用
子线程执行延时操作,执行完成后返回主线程更新界面
dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, );//子线程;
dispatch_async(queue, ^{
NSLog(@"%@---",[NSThread currentThread]);
NSURL *url=[NSURL URLWithString:@"http://img.hb.aicdn.com/1f2acbecdc6ac6187a9b02bffe4a5dedc9fe45ff15a44-D6LjC1_fw580"];
NSData *data=[NSData dataWithContentsOfURL:url];
UIImage *image=[UIImage imageWithData:data];\
NSLog(@"图片加载完毕");
/*************************开启子线程,加载图片*****************/
//[self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
/***********************************************************/
/*要求使用GCD的方式,在子线程加载图片完毕后,主线程拿到加载的image刷新UI界面。 线程间通信 从子线程回到主线程
*/ dispatch_queue_t queuemain=dispatch_get_main_queue();//主线程;
dispatch_async(queuemain, ^{
self.imageView.image=image;
NSLog(@"%@",[NSThread currentThread]); });
/**********************************************************/
});
线程7--GCD的基本使用的更多相关文章
- ios线程和GCD
1.什么是进程? 进程是指在系统中正在运行的一个应用程序.比如同时打开QQ.Xcode,系统就会分别启动2个进程.截图 2.什么是线程? 1).一个进程要想执行任务,必须得有线程(每一个进程至少要有一 ...
- 创建线程方式-GCD
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- ios线程和GCD和队列同步异步的关系
1.什么是进程? 进程是指在系统中正在运行的一个应用程序.比如同时打开QQ.Xcode,系统就会分别启动2个进程.截图 2.什么是线程? 1).一个进程要想执行任务,必须得有线程(每一个进程至少要有一 ...
- OC 线程操作 - GCD使用 -线程通讯, 延迟函数和一次性代码
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // [self downImag ...
- OC 线程操作 - GCD使用 -同步函数,异步函数,串行队列,并发队列
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // GCD 开几条线程并不是我们 ...
- Multithreading annd Grand Central Dispatch on ios for Beginners Tutorial-多线程和GCD的入门教程
原文链接:Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial Have you ever written a ...
- 队列 和 线程 之GCD dispatch
1.dispatch_queue_create 创建队列开启异步线程(1,4,2,3) // 创建一个队列 dispatch_queue_t queue = dispatch_queue_creat ...
- OC 线程操作 - GCD队列组
1.队列组两种使用方法2.队列组等待 wait /** 新方法 队列组一般用在在异步操作,在主线程写队列组毫无任何作用 */ - (void)GCD_Group_new_group___notify{ ...
- OC 线程操作 - GCD快速迭代
- (void)forDemo{ //全都是在主线程操作的 ; i<; i++) { NSLog(@"--%@", [NSThread currentThread]); } ...
- OC线程操作-GCD介绍
1. GCD介绍 1.11.2 1.3 异步具备开启能力但是不是 一定可以开启 1.4 1.5 67. 8.
随机推荐
- 修改ActiveReports验证文字“给不能为 null 的参数指定一个 null 值”
转:http://gcdn.gcpowertools.com.cn/showtopic-13759.html ActiveReports官方网站:http://www.gcpowertools.com ...
- C++单继承的构造函数和析构函数调用的顺序
1.继承构造函数调用顺序以及销毁的过程 先调用父类的构造函数,在调用子类的构造函数,析构函数调用相反.
- 小型Http服务器
HTTP又叫做超文本传输协议,现如今用的最多的版本是1.1版本.HTTP有如下的特点: 支持客户/服务器模式(C/S或B/S) 简单快速:基于请求和响应,请求只需传送请求方法和请求路径 灵活:HTTP ...
- JDBC连接数据库7个步骤
JDBC连接数据库 •创建一个以JDBC连接数据库的程序,包含7个步骤: 1.JDBC所需的四个参数(user,password,url,driverClass) (1)user用户名 ( ...
- 用postman做接口测试实例
使用postman做接口测试,可以选择请求方式,可以直接输入参数和header,可以编写测试结果的代码,判断是否通过测试 下图为填写接口测试地址.填写接口的参数,点击send发送请求 其中,Param ...
- eclip 重写从父类继承的方法的快捷操作
转载自http://blog.sina.com.cn/s/blog_53d599430101phlo.html 一.在代码中单击鼠标右键,在弹出的快捷菜单中选择“源代码(Source)”-&g ...
- h5 端图片上传
1.upload.js (function($) { $.extend($.fn, { images : new Array(), initImages:function (images) { $.e ...
- 第12章—使用NoSQL数据库—使用MongoDB+Jpa操作数据库
使用MongoDB+Jpa操作数据库 SpringData还提供了对多种NoSQL数据库的支持,包括MongoDB;neo4j和redis.他不仅支持自动化的repository,还支持基于模板的数据 ...
- 第5章—构建Spring Web应用程序—SpringMVC详解
SpringMVC详解 5.1.跟踪Springmvc的请求 SpringMVC的核心流程如下: 具体步骤: 第一步:发起请求到前端控制器(DispatcherServlet) 第二步:前端控制器请求 ...
- 【树】Construct Binary Tree from Inorder and Postorder Traversal
题目: Given inorder and postorder traversal of a tree, construct the binary tree. 思路: 后序序列的最后一个元素就是树根, ...