【发布时间】:2012-05-30 04:32:32
【问题描述】:
我在 ViewController 类中有 NSTimer.. 并且 NStimer 的所有方法都在该类中.. 我的 NSTimer 可以正常工作以进行播放和暂停...当我按下 iPhone 上的主页按钮时,计时器也正常工作(它从应用程序进入前台时应用程序进入后台的时间开始运行...当警报出现在屏幕上时,我的 NSTimer 正在运行(没有对警报做出响应)。我想停止 NSTimer 直到用户响应我的警报...之后我想启动 NSTimer...如何我可以这样做吗...?请帮助我...在此先感谢...我想从 Appdelegate.m 文件中调用 NSTimer 方法...我正在正确调用这些方法...并且调用了 ViewController 中的方法...但是该操作未执行。 .. 对于从 viewController 类调用时相同的方法,它正在工作......
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.
*/
}
【问题讨论】:
-
我已经编辑了我的问题.. 请看一次
-
请附上适用的代码,以便我们提供帮助!
-
我已包含代码..请检查一次..
-
是的...这里并不需要代码。使用 danh 指出的 UIAlertView 委托方法。
标签: iphone objective-c ios5 nstimer