国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS NSThread和NSOperation的基本使用詳解

2019-10-21 18:42:11
字體:
來源:轉載
供稿:網友

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];}

以上這篇iOS NSThread和NSOperation的基本使用詳解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 濮阳县| 平潭县| 沂南县| 镇原县| 进贤县| 新化县| 兖州市| 新龙县| 镇赉县| 宝兴县| 仪征市| 磐安县| 格尔木市| 永吉县| 遂昌县| 黎城县| 顺平县| 嵩明县| 赤壁市| 灌南县| 慈溪市| 沙湾县| 三亚市| 景宁| 湘潭市| 玉田县| 太湖县| 建德市| 获嘉县| 田林县| 时尚| 长泰县| 讷河市| 霸州市| 黄冈市| 建阳市| 彭泽县| 临武县| 阜康市| 德惠市| 嵊州市|