Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 优先化NSTimer_Objective C_Ios_Nstimer - Fatal编程技术网

Objective c 优先化NSTimer

Objective c 优先化NSTimer,objective-c,ios,nstimer,Objective C,Ios,Nstimer,我有一个NSTimer正在运行。应用程序正在与NSTimer同时执行许多操作(包括在同一视图控制器以及应用程序代理中)。我不知道为什么,但有时NSTimer会暂停,不更新标签。(对用户来说,它就像一个秒表。) 我应该用仪器来解决这个问题吗?要在被中断时对被调用的对象使用全局dispatch\u async()?或者有没有一种方法可以对NSTimer及其调用的方法进行优先级排序 我正在创建计时器,如下所示: oneSecondTicker = [NSTimer scheduledTimerWith

我有一个
NSTimer
正在运行。应用程序正在与
NSTimer
同时执行许多操作(包括在同一视图控制器以及应用程序代理中)。我不知道为什么,但有时
NSTimer
会暂停,不更新标签。(对用户来说,它就像一个秒表。)

我应该用仪器来解决这个问题吗?要在被中断时对被调用的对象使用全局
dispatch\u async()
?或者有没有一种方法可以对NSTimer及其调用的方法进行优先级排序

我正在创建计时器,如下所示:

oneSecondTicker = [NSTimer scheduledTimerWithTimeInterval:1.0 
                                                   target:self 
                                                 selector:@selector(updateLabelsWithOneSecondTicker) 
                                                 userInfo:nil
                                                  repeats:YES];

[[NSRunLoop currentRunLoop] addTimer:oneSecondTicker forMode:UITrackingRunLoopMode]; //!important

我们需要知道a)您是如何创建计时器的,b)您在计时器中执行的操作。否则我们只能猜测到底发生了什么。NSTimer调用的方法是否在主线程上?您可能希望确保在主线程上调用任何更新UI的代码。是的,我正在viewDidLoad中分配计时器。。。计时器是VC类的一个实例变量。当前:oneSecondTicker=[NSTimer scheduledTimerWithTimeInterval:1.0目标:自选择器:@selector(UpdateLabelSwithOneCondTicker)用户信息:无重复:是];如果使用
scheduledTimer…
方法创建计时器,则不需要使用
-[nsrunlop addTimer:forMode:][/code>将其作为创建过程的一部分添加到运行循环中。