标签:
1.线程间的通信:在一个进程中,线程往往不是独立存在的,多个线程之间需要经常进行通信。
2.线程间通信的体现:
一个线程传递数据给另一个线程
在一个线程执行完特定任务后,转到另一个线程继续执行任务
3.线程间通信常用方法:
—(void)performSelectorOnMainThread:(SEL)aselector withObject:(id)arg waitUntilDone:(BOOL)wait;
—(void)performSelector:(SEL)aselector onThread:(NSTread*)thr WithObject:(id)arg waitUntilDone:(BOOL)wait;
4.我们就用图表做示例:
5.代码如下:
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,strong)UIButton*button;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
[self UIButton];
}
-(void)UIButton{
self.button=[[UIButton alloc]initWithFrame:CGRectMake(130, 50, 100, 50)];
self.button.backgroundColor=[UIColor blueColor];
[self.button addTarget:self action:@selector(download) forControlEvents:UIControlEventTouchUpInside ];
[self.view addSubview:_button];
}
-(void)download{
//1.根据url下载图片
//从网络下载图片
NSURL * url = [NSURL URLWithString:@"http://img3.cache.netease.com/3g/2015/9/29/20150929110202279dd.png"];
//把图片转化为二进制
NSData*data = [NSData dataWithContentsOfURL:url];
//把数据转化成图片
UIImageView*image=[[UIImageView alloc]initWithFrame:CGRectMake(100, 300, 100, 80)];
image.image=[UIImage imageWithData:data];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
标签:
原文地址:http://www.cnblogs.com/jinchengvs/p/4846371.html