开发者

Problem with NSTimer called inside my -parserDidEndDocument

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜