码迷,mamicode.com
首页 > 其他好文 > 详细

NSOperation使用的三种方法

时间:2016-10-11 18:16:34      阅读:113      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!