我的代碼如下。我試圖在窗口中的屏幕上顯示一個計數器,並在計數限制結束後啓用按鈕。NSTimer未啓動預定方法
當我在nstimer之前運行代碼並且在nstimer之後只打印一次而沒有從時間倒計數功能打印任何東西時。有人會幫助我。
- (void)startTimer:(NSInteger)count;
{
NSLog(@"Entered the start timer function");
self.countLimit = count;
[self.lbCount setStringValue:[NSString stringWithFormat:@"%ld",self.countLimit]];
NSLog(@"Before nstimer");
@try{
self.timeCounter = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeCountDown) userInfo:nil repeats:YES];
}
@catch (NSException* e) {
NSLog(@"%@",[e description]);
}
NSLog(@"After nstimer");
}
- (void)timeCountDown
{
NSlog(@"Entered the function");
self.countLimit = self.countLimit - 1;
NSLog(@"Just entered the function time countdown");
if (self.countLimit < 0) {
NSLog(@"Entered count limit less than 0");
[self.timeCounter invalidate];
self.timeCounter = nil;
[self.btContinue setEnabled:YES];
return;
}
[self.lbCount setStringValue:[NSString stringWithFormat:@"%ld",self.countLimit]];
}
這不會有預定的延遲,但對他來說沒用。 – occulus