首页 > 其他 > 详细

NSOperation使用的三种方法

时间:2016-10-11 18:13:24      阅读:159      评论:0      收藏:0      [点我收藏+]

//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使用的三种方法

原文:http://www.cnblogs.com/PJXWang/p/5950138.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!