国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临高县| 巴中市| 鹤峰县| 丹东市| 松江区| 神池县| 达拉特旗| 武冈市| 灌云县| 罗甸县| 霍邱县| 二手房| 芦溪县| 云霄县| 建德市| 胶州市| 临西县| 东乡| 勐海县| 新和县| 维西| 锡林郭勒盟| 佛冈县| 田阳县| 东至县| 汶川县| 阿勒泰市| 青海省| 万山特区| 淳化县| 溧阳市| 长子县| 平和县| 锡林郭勒盟| 泗阳县| 惠州市| 车致| 阿尔山市| 维西| 阿拉尔市| 长泰县|