I have a label timer inside a UITableViewCell, using this code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]init];
timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(55, 26, 280, 25)];
timeLabel.text = [timeArray objectAtIndex:indexPath.row];
timeLabel.backgroundColor = [UIColor clearColor];
timeLabel.textColor = [UIColor blackColor];
[cell.contentView addSubview:timeLabel];
return cell;
NSLog(@"Title %@, time %@, second %@, time %i, tag %d", titleArray, timeArray, secondArray, time, button.tag);
}
And I have a timer that trigger by a button using this code
- (void)onoffBtn:(id)sender
{
countdownTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerElapsed:) userInfo:nil repeats:YES];
}
- (void) timerElapsed:(id)timer
{
if (time == 0)
{
[countdownTimer invalidate];
}
// this part only code for counting down timer
NSLog(@"%d:%d:%d", hour , minute, second);
}
If I put timeLabel.text = [NSString stringWithFormat:@"%d:%d:%d", hour , minute, second]; inside timerElapsed, of course it wont update my label inside cell.
So how do I update my label inside cell for every second?
Put
timeLabel.text = [NSString stringWithFormat:@"%d:%d:%d", hour , minute, second];insidecellForRowAtIndexPathand callreloadDatamethod of your tableview inside timerElapsed.I believe your hour, minute and second contain updated value.