ViewController クラスに NSTimer があります。そして、NStimer のすべてのメソッドはそのクラスにあります。アプリケーションがフォアグラウンドに入ったときにアプリケーションがバックグラウンドに入る時間)...私のアプリケーションでは、アプリケーションがフォアグラウンドに入るとすぐにアラートが発生しています(アプリケーションのUIAlertview didEnterForeGround)。ここで、アラートが画面に表示されているときに NSTimer が実行されています (アラートに応答しませんでした)。アラートに応答しているユーザーまで NSTimer を停止したい...その後、NSTimer を開始したい...方法それをしてもいいですか...?助けてください...事前に感謝します...Appdelegate.mファイルからNSTimerメソッドを呼び出したい...これらのメソッドを適切に呼び出しています...
enter code here
ViewController.h
+(ExamViewController *)evcInstance;
ViewController.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.
*/
}