Friday, 14 June 2013

Update UILabel continuously with time delay


 You can use NSTimer as
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f 
        target:self 
        selector:@selector(updateTimer:) 
        userInfo:nil 
        repeats:YES]; // Global Variable

And you can update your label in the func
- (void)updateTimer:(NSTimer *)theTimer {
    //static int countTime = 0; 
    countTime += 1;
    _timeOver=_timeOver-1; // Global Variable checks time
    NSString *s = [[NSString alloc] initWithFormat:@"Time left: %d", (_timeOver)];
    self._myTimeCounterLabel.text = s;
    [s release];
    if (_timeOver==0) {
        [self checkIfGameOver];
    }
}

No comments:

Post a Comment