ios学习(十九)NSThread简单使用
来源:互联网 发布:html源码怎么用 编辑:程序博客网 时间:2024/04/30 12:26
#import "ViewController.h"@interface ViewController ()-(void)printMuch;@property (weak, nonatomic) IBOutlet UIImageView *picImg;@end@implementation ViewController- (IBAction)buttonClicked:(id)sender {// [self printMuch];// [self createThread1];// [self createThread2];// [self createThread3];// [self downloadImage]; [NSThread detachNewThreadSelector:@selector(downloadImage) toTarget:self withObject:nil]; }-(void)downloadImage{ NSDate *begin = [NSDate date]; NSURL *url = [NSURL URLWithString:@"https://a-ssl.duitang.com/uploads/item/201504/03/20150403H4808_2QkBX.jpeg"]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *image = [UIImage imageWithData:data scale:2]; NSDate *end = [NSDate date]; //通知主线程更新ui// [self performSelectorOnMainThread:@selector(setDataToImageView:) withObject:image waitUntilDone:YES]; [self performSelector:@selector(setDataToImageView:) onThread:[NSThread mainThread] withObject:image waitUntilDone:YES]; NSLog(@"wo zai deng dai"); NSLog(@"%f", [end timeIntervalSinceDate:begin]); }-(void)setDataToImageView:(UIImage *)image{ [self.picImg setImage:image];}-(void) createThread1{ NSThread *tread = [[NSThread alloc] initWithTarget:self selector:@selector(printMuch) object:nil]; [tread start];}-(void)createThread2{ [NSThread detachNewThreadSelector:@selector(printMuch) toTarget:self withObject:nil];}-(void)createThread3{ [self performSelectorInBackground:@selector(printMuch) withObject:nil];}-(void)printMuch{ for (NSInteger i = 0; i < 10000; i++){ NSLog(@"%ld", (long)i); }}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- ios学习(十九)NSThread简单使用
- iOS 多线程之NSThread简单使用
- iOS多线程学习---NSThread
- NSThread的简单使用
- iOS多线程篇:NSThread简单介绍和使用
- 学习:NSThread的使用
- 多线程之NSThread简单使用
- iOS开发 ☞ NSThread使用
- iOS多线程学习(2)——NSThread和NSOperation
- IOS学习 多线程NSThread 消息循环(了解)涉及定时器
- iOS 学习笔记 --- 多线程基础(2)--- NSThread
- iOS多线程学习笔记(GCD、RunLoop、NSThread)
- iOS 多线程 NSthread的简单使用——iOS 编码复习(六)(多线程4)
- IOS开发学习笔记(十九)——Core Data使用(上篇)
- ROS学习--(十九)使用Gazebo模拟器
- ios学习路线—iOS高级(NSThread)
- iOS 多线程(一)NSThread
- ios多线程(NSThread)(swift)
- 技术团队的情绪与效率
- 使用Servlet处理http响应
- 嵌入式学习心得:关键字和宏定义
- Objective-C向前引用
- C语言总结(5)
- ios学习(十九)NSThread简单使用
- Android 低功耗蓝牙(BLE)开发(2)-- BluetoothAdapter详解
- vs2010设置堆栈大小
- WEB应用程序状态管理
- 【HTML5】图形组合
- 第二天 细说增删查改
- echo
- Android 无线调试 adb 命令
- class.getResource和class.getClassLoader().getResource()路径对比