Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Iphone my-parserDidEndDocument中调用的NSTimer有问题_Iphone_Objective C_Nstimer - Fatal编程技术网

Iphone my-parserDidEndDocument中调用的NSTimer有问题

Iphone my-parserDidEndDocument中调用的NSTimer有问题,iphone,objective-c,nstimer,Iphone,Objective C,Nstimer,我有一个NSTimer对象 timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(timerAction) userInfo:nil repeats:YES]; [timer fire]; 当从viewDidLoad方法调用计时器时,“timerAction”方法会完美地重复,但当我从parserDidEndDocument调用计时器时,“timerAction”方法只运行一次。这

我有一个NSTimer对象

timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
[timer fire];

当从viewDidLoad方法调用计时器时,“timerAction”方法会完美地重复,但当我从parserDidEndDocument调用计时器时,“timerAction”方法只运行一次。这是为什么?

您可以尝试在主线程上运行计时器

试试这个

创建一个包含代码的新方法,以启动计时器,如:-

-(void)createTimer{
    timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    [timer fire];
}
在您的
parserDidEndDocument
委托中,尝试以下操作:

[self performSelectorOnMainThread:@selector(createTimer) withObject:[nil waitUntilDone:YES]

您可以尝试在主线程上运行计时器

试试这个

创建一个包含代码的新方法,以启动计时器,如:-

-(void)createTimer{
    timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    [timer fire];
}
在您的
parserDidEndDocument
委托中,尝试以下操作:

[self performSelectorOnMainThread:@selector(createTimer) withObject:[nil waitUntilDone:YES]

您需要在调用计时器的parserDidEndDocument中发布代码。否则我怎么猜呢?上面是代码片段。这就是我放在ParserDind里的东西。即使在ViewDidLoad中,您也需要在调用计时器的parserDidEndDocument中发布代码。否则我怎么猜呢?上面是代码片段。这就是我放在ParserDind里的东西。即使在我看来,我也是天才!这是成功的!!!非常感谢。这是关于在主线程上运行的。代码中有一个小错误,它在[self-performSelectorOnMainThread:@selector(createTimer)with-Object:nil waitUntilDone:YES]下修复;我很高兴,这很有帮助。这个问题与线程有关,因为中的解析没有在主线程上完成。因此,在主线程上执行分配和与UIKit相关的任务,并让它按照Genius的方式处理事情,始终是一个好主意!这是成功的!!!非常感谢。这是关于在主线程上运行的。代码中有一个小错误,它在[self-performSelectorOnMainThread:@selector(createTimer)with-Object:nil waitUntilDone:YES]下修复;我很高兴,这很有帮助。这个问题与线程有关,因为中的解析没有在主线程上完成。因此,在主线程上执行分配和与UIKit相关的任务并让它相应地处理事情总是一个好主意