首页 > 编程语言 > 详细

NSThread 多线程 三种方式

时间:2014-12-09 00:31:59      阅读:329      评论:0      收藏:0      [点我收藏+]

//

//  ZBMainViewController.m

//  TestProject

//

//  Created by 张先森 on 14/12/5.

//  Copyright (c) 2014年 zhibin. All rights reserved.

//

 

#import "ZBMainViewController.h"

 

@interface ZBMainViewController ()

@property(nonatomic,strong)CALayer *mylayer;

 

 

@end

 

@implementation ZBMainViewController

 

 

 

 bool isopen=NO;

 

 

- (void)viewDidLoad {

    [super viewDidLoad];

 

    [self InitControls];

}

 

-(void)InitControls{

    NSThread *thread=[NSThread currentThread];

    NSLog(@"%@",thread);

    NSThread *mainthread=[NSThread mainThread];

    NSLog(@"%@",mainthread);

    

    

    NSThread *tempthread=[[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"线程1"];

    tempthread.name=@"thread1";

    

    [tempthread start];

    

    

    

    

    [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"线程2"];

    

    

    

    

    [self performSelectorInBackground:@selector(run:) withObject:@"线程3"];

}

 

-(void)run:(NSString *)str{

 

    NSLog(@"%@",str);

 

 

 

}

 

 

 

 

 

 

@end

 

NSThread 多线程 三种方式

原文:http://www.cnblogs.com/zhibin/p/4152275.html

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