您的位置:首页 > 移动开发 > IOS开发

IOS--静态多线程

2016-03-02 14:12 405 查看
TestController.m

#import "TestController.h"
#import "TestView.h"

@interface TestController()

@property(nonatomic,strong)UIButton *button;

@end

@implementation TestController

- (void)viewDidLoad
{
[super viewDidLoad];

_button = [UIButton buttonWithType:UIButtonTypeSystem];

_button.frame = CGRectMake(0, 20, 100, 20);
[_button setTitle:@"Hello" forState:UIControlStateNormal];

[_button addTarget:self action:@selector(start:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:_button];

}

-(void)start:(UIButton*)sender
{
//静态多线程
[NSThread detachNewThreadSelector:@selector(thLoop) toTarget:self withObject:nil];
}

-(void)thLoop
{
for (int i =1; i<=10 ; i++) {

//睡眠1秒
[NSThread sleepForTimeInterval:1];
NSLog(@"i=%d",i);
}

NSLog(@"end");

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: