IOS第一天多线程-04GCD通信
****
#define HMGlobalQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define HMMainQueue dispatch_get_main_queue() #import "HMViewController.h" @interface HMViewController ()
@property (weak, nonatomic) IBOutlet UIButton *button; @property (weak, nonatomic) IBOutlet UIImageView *newImageView;
@end @implementation HMViewController - (void)viewDidLoad
{
[super viewDidLoad]; [self newImageView]; // NSObject *obj = [NSObject new];
//
// [[NSObject alloc] init]; // Do any additional setup after loading the view, typically from a nib.
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
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];
});
});
} @end
IOS第一天多线程-04GCD通信的更多相关文章
- IOS第一天多线程-03线程间通信
**** #import "HMViewController.h" @interface HMViewController () @property (weak, nonatomi ...
- IOS第一天多线程-05GCD队列的使用
************** // // HMViewController.m // 08-GCD02-队列的使用(了解) // // Created by apple on 14-9-15. // ...
- IOS第一天多线程-02NSThread基本使用
**** #import "HMViewController.h" @interface HMViewController () @end @implementation HMVi ...
- IOS第一天多线程-01pthread
*** #import "HMViewController.h" #import <pthread.h> @interface HMViewController () ...
- iOS开发-多线程编程技术(Thread、Cocoa operations、GCD)
简介 在软件开发中,多线程编程技术被广泛应用,相信多线程任务对我们来说已经不再陌生了.有了多线程技术,我们可以同做多个事情,而不是一个一个任务地进行.比如:前端和后台作交互.大任务(需要耗费一定的时间 ...
- ios开发之多线程---GCD
一:基本概念 1:进程:正在运行的程序为进程. 2:线程:每个进程要想执行任务必须得有线程,进程中任务的执行都是在线程中. 3:线程的串行:一条线程里任务的执行都是串行的,假如有一个进程开辟了一条线程 ...
- 大厂常问iOS面试题--多线程篇
1.进程与线程 进程: 1.进程是一个具有一定独立功能的程序关于某次数据集合的一次运行活动,它是操作系统分配资源的基本单元. 2.进程是指在系统中正在运行的一个应用程序,就是一段程序的执行过程,我们可 ...
- iOS开发之多线程技术
本篇争取一篇讲清讲透,依然将通过四大方面清晰的对iOS开发中多线程的用法进行详尽的讲解: 一.什么是多线程 1)多线程执行原理 2)线程与进程 3)多线程的优缺点 二.我们为什么要用多线程编程技术 三 ...
- IOS编程之多线程
IOS编程之多线程 目录 概述——对多线程的理解 IOS中实现多线程的三种方式 NSThread 线程创建 线程的同步与锁 线程间的交互 线程的操作方法 NSOperation and NSOpera ...
随机推荐
- 原生 js 模拟 alert 弹窗
复制头部的 js 代码到你的 js 文件的任何地方,调用Chef.alert方法传入相应的参数即可并没有什么功能,只是一个提示的作用,可能样式比 alert 的弹窗好看点,css是写在js里的,只要你 ...
- Codeforces Round #346 (Div. 2)
前三题水 A #include <bits/stdc++.h> typedef long long ll; const int N = 1e5 + 5; int main() { int ...
- 转载:robotium typeText与enterText区别
solo.typeText和solo.enterText方法都可以对EditeText进行测试,达到的测试目的是一样的.存在几点不同: 1.实现上,typeText方法是robotium框架调用系统I ...
- Squid的简单使用
1. squid配置 # Squid normally listens to port http_port hosts_file /etc/hosts cache_access_log /var/lo ...
- [转]shell 变量替换
转自:http://blog.csdn.net/xuhongning/article/details/6191515 1,参数替换: 不含有“:”的,只要定义了,就生效,不管是否为空 含有“:”的,即 ...
- flex设置成1和auto有什么区别
首先明确一点是, flex 是 flex-grow.flex-shrink.flex-basis的缩写.故其取值可以考虑以下情况: flex 的默认值是以上三个属性值的组合.假设以上三个属性同样取默认 ...
- iOS中为网站添加图标到主屏幕
1 <link rel="apple-touch-icon-precomposed" href="icon.png"/> 2 <link re ...
- Android 通信 EventBus
参考: Android 框架炼成 教你如何写组件间通信框架EventBus Android EventBus源码解析 带你深入理解EventBus Android EventBus实战 没听过你就ou ...
- ACM Longest Repeated Sequence
Description You are given a sequence of integers, A = a1, a2, ... an. A consecutive subsequence of A ...
- ACM:统计难题 解题报告-字典树(Trie树)
统计难题 Time Limit:2000MS Memory Limit:65535KB 64bit IO Format:%I64d & %I64u Submit Status ...