我创建了一个新线程来学习iOS的runloop。 在我的NSThread子类中:
@implementation TestThread
-(void)main
{
NSRunLoop *currentThreadRunLoop = [NSRunLoop currentRunLoop];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(handleTimerTask) userInfo:nil repeats:YES];
[currentThreadRunLoop runMode:NSDefaultRunLoopMode beforeDate: [NSDate distantFuture]];
}
-(void) handleTimerTask
{
NSLog(@"I am in timer task!");
}
@end
将显示该消息。但是当我在runloop启动后放置计时器时,它无法打印消息?有人可以帮帮我吗?感谢。
-(void)main
{
NSRunLoop *currentThreadRunLoop = [NSRunLoop currentRunLoop];
[currentThreadRunLoop runMode:NSDefaultRunLoopMode beforeDate: [NSDate distantFuture]];
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(handleTimerTask) userInfo:nil repeats:YES];
}
-(void) handleTimerTask
{
NSLog(@"I am in timer task!");
}
@end
答案 0 :(得分:0)
简单而基本的是,如果运行UIApplication的runloop,它将阻止所有操作并使UI无响应