я пытаюсь использовать этот код, но я получил ошибку "timeLabel undeclared"
как мне объявить timeLabel. спасибо ..
спасибо заранее ... попробуй заставить таймер работать, но с кодом кажется, что там какая-то ошибка ..
//In Header
int timeSec = 0;
int timeMin = 0;
NSTimer *timer;
//Call This to Start timer, will tick every second
-(void) StartTimer
{
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
}
//Event called every time the NSTimer ticks.
- (void)timerTick:(NSTimer *)timer
{
timeSec++;
if (timeSec == 60)
{
timeSec = 0;
timeMin++;
}
//Format the string 00:00
NSString* timeNow = [NSString stringWithFormat:@"%02d:%02d", timeMin, timeSec];
//Display on your label
[timeLabel setStringValue:timeNow];
}
//Call this to stop the timer event(could use as a 'Pause' or 'Reset')
- (void) StopTimer
{
[timer invalidate];
timeSec = 0;
timeMin = 0;
//Since we reset here, and timerTick won't update your label again, we need to refresh it again.
//Format the string in 00:00
NSString* timeNow = [NSString stringWithFormat:@"%02d:%02d", timeMin, timeSec];
//Display on your label
[timeLabel setStringValue:timeNow];
}