【发布时间】:2014-12-20 13:18:45
【问题描述】:
当我的应用关闭时,我希望它在 viewController.m 中调用 void 方法
我试过了:
我在viewController.h 中声明了NSTimer(alarmm) 和void(alarm:),并且我在Appdelegate.m 中导入了viewController.h
AppDelegate.m:
- (void)applicationDidEnterBackground:(UIApplication *)application{
alarmm = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(alarm:) userInfo:nil repeats:YES];
}
但是当它运行时
**2014-12-20 13:53:19.881 protect my phone[3292:959295] -[AppDelegate alarm:]: unrecognized selector sent to instance 0x170043810
2014-12-20 13:53:19.884 protect my phone[3292:959295] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AppDelegate alarm:]: unrecognized selector sent to instance 0x170043810'
*** First throw call stack:
(0x182e5659c 0x1935600e4 0x182e5d664 0x182e5a418 0x182d5eb6c 0x183d2ae18 0x182e0e8d8 0x182e0e588 0x182e0bfd4 0x182d390a4 0x18bee35a4 0x18766e3c0 0x10000a320 0x193bcea08)
libc++abi.dylib: terminating with uncaught exception of type NSException**
【问题讨论】:
-
仅供参考:一旦您的应用程序进入后台并随后被挂起,将不会触发任何计时器。
标签: ios objective-c uiviewcontroller nstimer appdelegate