NSOperation使用的三种方法
Posted PJXWang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NSOperation使用的三种方法相关的知识,希望对你有一定的参考价值。
//1.invacationOperation
-(void)invocationOperation
{
NSInvocationOperation *ip = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(operation ) object:nil];
[ip start];
// [self performSelector:@selector(operation) withObject:nil];
}
//2.blockOperation
-(void)blockOperation
{
NSBlockOperation *bp = [NSBlockOperation blockOperationWithBlock:^{
//在主线程中完成
NSLog(@"--1--%@",[NSThread currentThread]);
}];
//额外任务在子线程完成
[bp addExecutionBlock:^{
NSLog(@"--2--%@",[NSThread currentThread]);
}];
[bp start];
//3.自定义PJXCustomOperation继承NSOperation
#import <Foundation/Foundation.h>
@interface PJXCustomOperation : NSOperation
@end
#import "PJXCustomOperation.h"
@implementation PJXCustomOperation
//在实现文件中实现-main方法
-(void)main
{
NSLog(@"--1--%@",[NSThread currentThread]);
}
//自定义
-(void)customOperation
{
PJXCustomOperation *cp = [[PJXCustomOperation alloc]init];
}
}
-(void)operation
{
NSLog(@"---1---%@",[NSThread currentThread]);
}
以上是关于NSOperation使用的三种方法的主要内容,如果未能解决你的问题,请参考以下文章