现在我知道有关于 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];
}
}