我在 ViewController 类中有 NSTimer.. NStimer 的所有方法都在该类中.. 我的 NSTimer 在播放和暂停方面工作正常......当我按下 iPhone 上的主页按钮时,计时器也工作正常(它开始运行从当应用程序进入前台时应用程序进入后台的时间... 在这里,当警报出现在屏幕上时,我的 NSTimer 正在运行(没有对警报做出响应)。我想停止 NSTimer 直到用户响应我的警报...之后我想启动 NSTimer...如何我可以这样做吗...?请帮助我...在此先感谢...我想从 Appdelegate.m 文件中调用 NSTimer 方法...我正在正确调用这些方法...
enter code here
视图控制器.h
+(ExamViewController *)evcInstance;
视图控制器.m
ExamViewController *evc = nil;
@implementation ExamViewController
+(ExamViewController *)evcInstance
{
if(!evc)
{
evc = [[ExamViewController alloc] init];
}
return evc;
}
- (void)onStartPressed
{
stopwatchtimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:stopwatchtimer forMode:NSRunLoopCommonModes];
resume.hidden = YES;
resume.enabled=NO;
pause.hidden = NO;
pause.enabled=YES;
}
- (void)onStopPressed
{
[stopwatchtimer invalidate];
stopwatchtimer = nil;
pause.hidden = YES;
pause.enabled=NO;
resume.hidden = NO;
resume.enabled=YES;
}
Appdelegate.m
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[ExamViewController evcInstance] onStopPressed];
NSLog(@"applicationWillEnterForeground");
if(viewCalled ==YES)
{
UIAlertView *alertview=[[UIAlertView alloc]initWithTitle:@"" message:@"DO! You Want To continue" delegate:self cancelButtonTitle:@"YES" otherButtonTitles:@"NO", nil];
[alertview show];
[alertview release];
}
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}