“我正在使用自定义单元格类来显示它成功显示的时间,但问题是当我向下滚动表格视图时,然后那个计时器标签没有显示。我已经使用了这个代码,但是当我向下滚动并再次向上滚动的单元格标签时计时器隐藏,我不知道如何解决这个问题“
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"%d_%d",indexPath.section,indexPath.row];
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[MyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell=customCell;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell = (MyCell *)[tableView cellForRowAtIndexPath:indexPath];
[cell startTimer:indexPath];
}
//这里是mycell类代码
- (void) startTimer:(NSIndexPath *)indexPath
{
if (self.timer)
[self.timer invalidate];
currentIndexPath=indexPath;
self.secondsLeft=10;
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(calculateTimer) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
[self.timer fire];
}
- (void)calculateTimer
{
if (self.secondsLeft >0)
{
self.secondsLeft --;
self.timeLbl.text=[NSString stringWithFormat:@"0%d",self.secondsLeft];
self.showLbl.text=[NSString stringWithFormat:@"0%d",self.secondsLeft];
}
if (self.secondsLeft==0)
{
[self.timer invalidate];
self.timeLbl.text=@"";
}
}
-(void)showTimer
{
self.timeLbl.text=[NSString stringWithFormat:@"%d",self.secondsLeft];
NSLog(@"this is self second%d",self.secondsLeft);
}