码迷,mamicode.com
首页 > 编程语言 > 详细

NSThread 多线程 三种方式

时间:2014-12-09 00:33:30      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:io   ar   sp   for   strong   on   2014   art   log   

//

//  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 多线程 三种方式

标签:io   ar   sp   for   strong   on   2014   art   log   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!