开发者

Problem with NSTimer called inside my -parserDidEndDocument

开发者 https://www.devze.com 2023-02-09 18:26 出处:网络
I have a NSTimer object. timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];

I have a NSTimer object.

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

The method 'timerAction' repeats perfectly when call the timer from viewDidLoad method, but when I call the timer from parserDidEndDocument, the method 'timerAction' runs on开发者_运维知识库ly once. Why is this?


you can try running the timer on the main thread.

Try this

create a new method that includes the code, to start timer, like :-

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

In Your parserDidEndDocument delegate, try this:

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

精彩评论

暂无评论...
验证码 换一张
取 消