在带有 ARC 的 ios5.0 中,在我的 rootviewcontroller 中,我调用由应用程序委托持有的安全管理器对象中的方法。在该方法中,我设置计时器如下
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self
selector:@selector(updateModel:) userInfo:str repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
但是,这永远不会触发选择器,即。 updateModel:永远不会被调用。可能出了什么问题?是否有另一种更有效的方法可以在不使用 NStimer 的情况下做到这一点?
也可能是线程问题:
if
[NSThread isMainThread]
为 false 则启动计时器,如下所示:
dispatch_async(dispatch_get_main_queue(), ^{
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)