timeIntervalSinceNow错误用于暂停和恢复计时器

时间:2012-06-18 20:56:28

标签: iphone

在我的代码中使用暂停计时器和恢复计时器来暂停和恢复计时器。得到了错误 'NSInvalidArgumentException', reason: '-[__NSCFNumber timeIntervalSinceNow]: unrecognized selector sent to instance 0x164590'

暂停计时器和恢复计时器的代码

-(void)pauseTimer{
pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain];
previousFireDate = [[timer fireDate] retain];
[timer setFireDate:[NSDate distantFuture]];
}
-(void)resumeTimer{
float pauseTime = -1*[pauseStart timeIntervalSinceNow];
[timer setFireDate:[previousFireDate initWithTimeInterval:pauseTime sinceDate:previousFireDate]];
[pauseStart release];
[previousFireDate release];
}

在播放暂停切换按钮

中使用暂停和恢复计时器
-(void)playpauseAction:(id)sender {
if([audioPlayer isPlaying])
{
    [sender setImage:[UIImage imageNamed:@"Play Icon.png"] forState:UIControlStateSelected];
    [audioPlayer pause];
    [self pauseTimer];
}
else
{
    [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    [audioPlayer play];
    [self resumeTimer];
    if(isFirstTime == YES)
    {
        self.timer = [NSTimer scheduledTimerWithTimeInterval:11.0
                                            target:self
                                            selector:@selector(displayviewsAction:)
                                            userInfo:nil
                                            repeats:NO];
        isFirstTime  = NO;
    }    
} 
}

知道应用终止的原因以及如何解决此问题。

感谢。

1 个答案:

答案 0 :(得分:1)

resumeTimer被调用两次pauseStartpreviousFireDate被过度释放且应用程序可能崩溃时!