NSThread 多线程 三种方式

我的梦境 提交于 2020-03-20 02:05:01

//

//  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

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!