NSThread適合簡單的耗時任務(wù)的執(zhí)行,它有兩種執(zhí)行方法
為象州等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及象州網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站制作、做網(wǎng)站、象州網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
- (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適合需要復(fù)雜的線程調(diào)度的方法,然后它默認(rèn)是使用主線程不會創(chuàng)建子線程
- (void)threeClick{
// 1.創(chuàng)建NSInvocationOperation對象
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(run) object:nil];
// 2.調(diào)用start方法開始執(zhí)行操作
[op start];
}
- (void)run
{
NSLog(@"------%@", [NSThread currentThread]);
}
- (void)fourClick{
NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{
// 在主線程
NSLog(@"1------%@", [NSThread currentThread]);
}];
// 添加額外的任務(wù)(在子線程執(zhí)行)
[op addExecutionBlock:^{
NSLog(@"2------%@", [NSThread currentThread]);
}];
[op addExecutionBlock:^{
NSLog(@"3------%@", [NSThread currentThread]);
}];
[op addExecutionBlock:^{
NSLog(@"4------%@", [NSThread currentThread]);
}];
[op start];
}
以上這篇iOS NSThread和NSOperation的基本使用詳解就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持創(chuàng)新互聯(lián)。
文章題目:iOSNSThread和NSOperation的基本使用詳解
文章轉(zhuǎn)載:http://aaarwkj.com/article40/jjgpho.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、定制網(wǎng)站、品牌網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、搜索引擎優(yōu)化、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)