在关闭和打开窗口时暂停和恢复可重复的ntimer



现在我知道有关于NSTimer暂停的问题,但没有关于可重复和关闭/打开窗口的问题。切换暂停工作完美(使用按钮勾选)。重新打开窗口会出现BAD_ACCESS错误。

- (void)awakeFromNib
{
    self.timer = [[NSTimer scheduledTimerWithTimeInterval:0.85
                                               target:self
                                             selector:@selector(populateTable:)
                                             userInfo:nil
                                              repeats:YES] retain];
}
-(IBAction)fireUpTableWindow:(id)sender
{
    [aTableWindow makeKeyAndOrderFront:self];
    [self resumeTimer:timer];
}

NSDate *pauseStart, *previousFireDate;
-(void) pauseTimer:timer
{
    pauseStart = [[NSDate dateWithTimeIntervalSinceNow:0] retain];    
    previousFireDate = [[timer fireDate] retain];
    [timer setFireDate:[NSDate distantFuture]];
}
-(void) resumeTimer:timer
{
    float pauseTime = -1*[pauseStart timeIntervalSinceNow];
    [timer setFireDate:[previousFireDate initWithTimeInterval:pauseTime sinceDate:previousFireDate]];
    [pauseStart release];
    [previousFireDate release];
}
- (IBAction)closeTableWindow:(id)sender
{
    [self pauseTimer:timer];
    [self->aTableWindow close];
    [self release];
}
}

重新打开窗口会出现BAD_ACCESS错误。

检查Interface Builder中窗口是否未设置为在关闭时释放

相关内容

  • 没有找到相关文章

最新更新