当我的应用程序关闭时,我希望它在 viewController.m
中调用 void 方法
我试过这个:
我已经声明了 NSTimer
(警报)和void(alarm:)
在 viewController.h
我已经导入了viewController.h
在 Appdelegate.m
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**
最佳答案
正如你所说,你声明了 alarm
在某些 View Controller 中,但您尝试在 AppDelegate
上调用它, 没有定义的地方。
因此,您会因 self 上无法识别的选择器而崩溃。
尝试在 NSTimer
中交换自我创建到 View Controller 引用...
关于ios - 如何从我的应用程序委托(delegate)启动一个 NSTimer,它调用我在 Viewcontroller.m 中的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27580627/