开发者

Unpause this NSTimer?

I am pausing an NSTimer like so:

- (IBAction)pause 
{
    pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain];
    previousFiringDate = [stopmusictimer fireDate];
    NSDate *date = [NSDate distantFuture];
    [stopmusictimer setFireDate:date]; 
}

I have another IBAction:

- (IBAction)unpausebu开发者_JS百科tton 
{
    // dunno code
}

But I am not sure how to unpause the NSTimer now. Anyone, please help me! Thanks


NSTimer instances weren't really designed to be dynamically mucked with; the setFireDate: explicitly documents that doing so is relatively expensive. Probably similar to just invalidating the old one and creating a new one.

If you are pausing the timer and then your "unpause" is always "fire right now", I'd suggest invalidating and releasing the timer on pause (release only if necessary) then simply calling the targeted method on unpause.

That would be a more typical pattern.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜