【问题标题】:reloadRowsAtIndexPaths causes cell to blink or flickerreloadRowsAtIndexPaths 导致单元格闪烁或闪烁
【发布时间】:2014-11-07 19:48:29
【问题描述】:

我有一个表格视图,其中每个单元格都可以播放音频文件。我正在尝试复制语音备忘录程序中的单元格:

我正在使用 UISlider 提供播放栏,并且我有当前时间和剩余时间的文本标签。我希望在播放时更新单元格中的数据。

要为 UISlider 设置动画,我调用该方法:

UIView.animateWithDuration(Double(player.duration) - Double(player.currentTime), delay: 0, options: .AllowUserInteraction | .BeginFromCurrentState, animations: {
    cell.audioSlider.setValue(Float(self.duration) - Float(self.player.currentTime), animated: true)
    self.startToPlay = false
}, completion: { _ in
    cell.audioSlider.setValue(Float(self.player.currentTime), animated: true)})

在我使用计时器的时候:

timer = NSTimer.scheduledTimerWithTimeInterval(NSTimeInterval(interval), target: self, selector: "updateProgressBar:", userInfo: nil, repeats: true)

updateProgressBar 函数用于更新文本标签。 如果我在计时器的每个间隔调用 reload 方法,那么单元格就会闪烁。

tableView.reloadRowsAtIndexPaths([currentCellIndexPath], withRowAnimation: .Automatic)

有没有办法在不调用reloadRowsAtIndexPaths的情况下更新单元格中的值?

【问题讨论】:

    标签: ios uitableview swift timer


    【解决方案1】:

    存储对您希望更新标签的单元格 (NSIndexPath) 的引用,然后直接编辑它们。

    返回指定索引路径的表格单元格。

    • (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath 参数 索引路径 在接收器中定位行的索引路径。

    返回值 表示表格单元格的对象,如果单元格不可见或 indexPath 超出范围,则为 nil。

    类似这样的东西。

    SomeCell *cell = (SomeCell*)[self.yourTableView cellForRowAtIndexPath:_yourStoredIndexPath];
    cell.someLabel.text = @"Some text";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      • 2012-07-23
      相关资源
      最近更新 更多