IOS NSThread和NSOperation基本使用
来源:互联网 发布:淘宝店铺推广流程 编辑:程序博客网 时间:2024/05/22 12:40
NSThread适合简单的耗时任务的执行,它有两种执行方法
- (void)oneClick{ [NSThread detachNewThreadSelector:@selector(doSomething:) toTarget:self withObject:@"oneClick"];}-(void)doSomething:(NSString*) str{ NSLog(@"%@",str);}- (void)twoClick{ NSThread* myThread = [[NSThread alloc] initWithTarget:self selector:@selector(doSomething:) object:@"twoClick"]; [myThread start];}
NSOperation适合需要复杂的线程调度的方法,然后它默认是使用主线程不会创建子线程
- (void)threeClick{ // 1.创建NSInvocationOperation对象 NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(run) object:nil]; // 2.调用start方法开始执行操作 [op start];}- (void)run{ NSLog(@"------%@", [NSThread currentThread]);}- (void)fourClick{ NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{ // 在主线程 NSLog(@"1------%@", [NSThread currentThread]); }]; // 添加额外的任务(在子线程执行) [op addExecutionBlock:^{ NSLog(@"2------%@", [NSThread currentThread]); }]; [op addExecutionBlock:^{ NSLog(@"3------%@", [NSThread currentThread]); }]; [op addExecutionBlock:^{ NSLog(@"4------%@", [NSThread currentThread]); }]; [op start];}
阅读全文
0 0
- IOS NSThread和NSOperation基本使用
- IOS_1,ios多线程使用:NSThread和NSOperation异步加载图片
- iOS多线程NSThread/GCD/NSOperation区别和使用
- iOS多线程之NSThread、NSOperation和GCD
- iOS多线程NSThread,NSOperation和GCD详解
- iOS NSOperation基本使用
- iOS 多线程的实现与使用(NSThread, NSOperation, GCD)
- iOS多线程学习(2)——NSThread和NSOperation
- 关于IOS中GCD,NSThread和NSOperation的一些总结
- 转载【iOS多线程NSThread,NSOperation和GCD详解】
- iOS 多线程NSThread、NSOperation、GCD
- iOS多线程NSThread/NSOperation/GCD
- IOS多线程(NSThread,NSOperation,GCD)
- iOS 多线程NSThread-NSOperation-GCD
- iOS多线程 GCD NSoperation NSThread
- iOS多线程(NSThread、NSOperation、GCD)
- [笔记]iOS开发之多线程GCD和NSOperation基本使用
- [多线程]NSThread, NSOperation 和 GCD
- 视频编码基础之I帧 、P帧、B帧
- web项目调用arcgis api for JS离线包报“https://[HOSTNAME_AND_PATH_TO_JSAPI]dojo/...”错误解决方法
- 我们与五位大咖聊了聊,创业“独角兽”应具备的气质?
- “技术男”如何创业,他总结了一套避坑指南
- 管理员身份启动VS
- IOS NSThread和NSOperation基本使用
- REDIS (15) JedisPool的参数testoncreate,testWhileIdle,testonborrow和testonreturn
- 242. Valid Anagram
- python 参数详解
- 简述JVM基础(六):虚拟机字节码执行引擎
- 天池历届大赛答辩PPT及视频
- lab1
- 深入理解java虚拟机 摘要(一)
- lombok的简单粗暴的作用