- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent *)event {
//1 新建狀態(tài)
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(demo) object:nil];
//2 就緒狀態(tài)? --》 運(yùn)行狀態(tài)
[thread start];
}
- (void)demo {
for (int i = 0 ; i < 10; i++) {
if (i == 5) {
//3 睡眠狀態(tài)
[NSThread sleepForTimeInterval:5];
}
if (i == 7) {
//4 死亡狀態(tài)
[NSThread exit];
}
NSLog(@"hello %d",i);
}
}