标签:
@interface HMViewController ()
@property (nonatomic, strong) NSThread *thread;
@end
@implementation HMViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil];
self.thread.name = @"线程A";
}
- (void)test
{
NSLog(@"test - 开始 - %@", [NSThread currentThread].name);
// [NSThread sleepForTimeInterval:5]; // 阻塞状态
// NSDate *date = [NSDate dateWithTimeIntervalSinceNow:5.0];
// [NSThread sleepUntilDate:date];
for (int i = 0; i<1000; i++) {
NSLog(@"test - %d - %@", i, [NSThread currentThread].name);
if (i == 50) {
[NSThread exit];
}
}
NSLog(@"test - 结束 - %@", [NSThread currentThread].name);
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// 开启线程
[self.thread start];
}
@end
标签:
原文地址:http://www.cnblogs.com/cnios/p/4574716.html