【问题标题】:Allow UITableViewCell to update content even when scrolling [duplicate]即使在滚动时也允许 UITableViewCell 更新内容[重复]
【发布时间】:2013-12-24 03:33:46
【问题描述】:

我有一个UITableView,其中包含一个自定义UITableViewCell,其中包含时间(精确到毫秒)。滚动时,时间文本直到滚动停止后才会更新。我知道这可能是大多数人想要的默认行为,但我希望单元格即使在滚动时也能保持更新。有没有办法做到这一点?我在文档中找不到任何内容。

单元格使用NSTimer 每秒递归调用更新时间函数 30 次。此函数更新单元格上的 UILabel。

【问题讨论】:

    标签: ios objective-c uitableview


    【解决方案1】:

    查看this answer 以获得一些深入阅读。长话短说,您需要将计时器设置为在普通模式下运行。这样它会在其他东西占用 UI 线程时更新。这就是我使用我的方式:

    downloadAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(animateDownloadButtons) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:downloadAnimationTimer forMode:NSRunLoopCommonModes];
    

    【讨论】:

      【解决方案2】:

      使用 UITableViewDelegate。滚动 tableView 时调用此方法。

      - (void)scrollViewDidScroll:(UIScrollView *)scrollView
      {
          NSArray* arrayVisibleCells = [tableViewContent visibleCells];
      
          for (UITableViewCell* cell in arrayVisibleCells)
          {
              //update code
          }
      }
      

      【讨论】:

      • 这既不工作也不回答问题
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多