0

在我的代码中使用暂停计时器和恢复计时器来暂停和恢复计时器。出现错误 '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;
    }    
} 
}

知道应用程序为何终止以及如何解决此问题。

谢谢。

4

1 回答 1

1

resumeTimer被调用两次pauseStart并被previousFireDate过度释放并且应用程序可能崩溃!

于 2012-06-18T23:04:33.390 回答