私のコードを以下に示します。ウィンドウの画面にカウンターを表示し、カウント制限が終了した後にボタンを有効にしようとしています。
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]];
}