代码之家  ›  专栏  ›  技术社区  ›  iPatel

UITableViewCell上的倒计时计时器,UITableView的滚动/滞后问题

  •  0
  • iPatel  · 技术社区  · 11 年前

    根据我的标题,我有一个表视图,它在每一行中显示彩票,每张彩票都有它的详细视图。门票有自己的抽签时间。 动态票显示在表视图上,现在考虑表上的10到15张票。第一次一切都很好。

    但当我上下滚动表5到6次或详细查看票5到6遍时,表就会挂起。 问题只是NSTimer,我每秒钟重复一次计时器。当我被移除计时器时,桌子并没有被悬挂。 我还试图通过以下代码来删除单元的可重用性,但并没有奏效。

    NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; // I know it's bad for us. :(
    

    我也是 isValid 和 nil 创建之前 timer 有人提出过这样的问题吗?有人能给我解决问题的建议吗?

    1 回复  |  直到 11 年前
        1
  •  1
  •   iPatel    11 年前

    花了11个小时后,我找到了解决办法。早些时候我在做什么?我用 repeats:YES 所以计时器的方法将每1分钟连续调用一次。问题就是这样发生的。

    我删除了每行的每个计时器的逻辑,并将单个计时器放入 viewWillAppear (或者你想放什么) 方法应用 重复:是 在计时器的方法中使用以下逻辑

    - (void) calculateTimer
    {
        // Here count down timer is only for visible rows not for each rows.
    
        NSArray *listOFCurrentCell = [myTableView visibleCells]; // Returns the table cells that are visible in the table view.
        for(customCell *theMycustomCell in listOFCurrentCell)
        {
            => Here I put logic of count down timer
            => It's will be only for those row that display currently 
        }
    }
    

    希望上面的逻辑适用于像我这样有同样问题的人。