【发布时间】:2011-07-27 14:00:07
【问题描述】:
我有一个关于 xcode 中的多线程的问题。我搜索了许多网站,但仍然无法让我的应用程序正常工作。即使按下主页按钮,我也想每 5 秒重复一次,即继续在后台计时。以下是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
[NSThread detachNewThreadSelector:@selector(test) toTarget:self withObject:nil];
}
在test.m中,
-(void)test {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(sayYeah) userInfo:nil repeats:YES];
[pool release];
}
在sayYeah.m中,
-(void)sayYeah {
NSLog(@"yeah");
}
我期望的是“是的”将继续每 5 秒弹出一次,即使按下主页按钮。但它没有,谁能知道应该如何实现多线程?谢谢!
【问题讨论】:
标签: iphone multithreading xcode background nstimer