国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 井冈山市| 襄垣县| 林西县| 潞城市| 中山市| 施甸县| 大田县| 白河县| 姚安县| 黄大仙区| 厦门市| 金寨县| 衡东县| 古丈县| 寿光市| 玉山县| 克拉玛依市| 蓝山县| 社旗县| 平陆县| 清新县| 德化县| 乐都县| 登封市| 五台县| 临漳县| 陆良县| 杂多县| 兴海县| 蕉岭县| 江门市| 商城县| 鄂伦春自治旗| 喀什市| 通海县| 芷江| 通州区| 图们市| 江油市| 本溪| 晋州市|