这里有点菜鸟。
我正在开发一个可以播放一些循环声音的应用程序。我想让用户能够使用计时器在一定时间后关闭应用程序。这个想法是用户按下一个按钮,一旦计时器耗尽,应用程序就会关闭。
此时,如果按下按钮,应用程序就会崩溃。
这是我到目前为止得到的:
- (IBAction)timer:(id)sender{
timer = [NSTimer scheduledTimerWithInterval: 10.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES];
}
-(void) targetMethod: (NSTimer*) theTimer {
NSLog(@"timer?");
exit(0);
}
最佳答案
您需要正确定义计时器引用:
NSTimer *timer = [NSTimer scheduledTimerWithInterval: 10.0 target:self selector:@selector(targetMethod:) userInfo:nil repeats: YES];
关于iphone - 使用 NSTimer 关闭应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4412460/