开发者

Dynamically generated NSTimers in same UITableview?

I'm trying to implement a timer into a new application. One use case that is likely is to have more than开发者_JAVA百科 one timer running at a time in the same view updating a UILabel or UIButton title text.

Does anyone have experience of doing this? what approach would you suggest.

The difficulty is when the timers fire off the same selector in short succession.

many thanks in advance

Nick


In .h file declare object:

NSTimer *myTimer1,myTimer2;

In .m file:

myTimer1 = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(nextPhoto) userInfo:nil repeats:YES];
myTimer2 = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(nextPhoto) userInfo:nil repeats:YES];

After the above invalidate the timers like this:

[myTimer1 invalidate];
[myTimer2 invalidate];

Try it like this.


If you do create repeating timers dynamically, you can run into problems with timer invalidation. I'd suggest you use performSelector:withObject:afterDelay: or performSelectorOnMainThread:withObject:waitUntilDone: methods instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜