我在 a 中有一个标签计时器UITableViewCell
,使用此代码
- (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);
}
我有一个使用此代码通过按钮触发的计时器
- (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);
}
如果我放在timeLabel.text = [NSString stringWithFormat:@"%d:%d:%d", hour , minute, second];
里面timerElapsed
,当然它不会更新我在单元格内的标签。
那么如何每秒更新单元格内的标签?