reloadRowsAtIndexPaths导致单元格闪烁或闪烁

时间:2014-11-07 19:48:30

标签: ios uitableview swift timer

我有一个tableview,其中每个单元格都包含播放音频文件的功能。我试图复制语音备忘录程序中找到的单元格:

http://i.imgur.com/J9d5ECM.png

我使用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函数用于更新文本标签。 如果我在计时器的每个间隔调用重载方法,则单元格会闪烁。

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

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

1 个答案:

答案 0 :(得分:1)

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

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

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

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

与此类似的东西。

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