我有一个tableview,其中每个单元格都包含播放音频文件的功能。我试图复制语音备忘录程序中找到的单元格:
我使用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
的情况下更新单元格中的值?
答案 0 :(得分:1)
存储对您希望更新标签的单元格(NSIndexPath)的引用,然后直接编辑它们。
返回指定索引路径的表格单元格。
返回值 表示表格单元格的对象,如果单元格不可见或indexPath超出范围,则为nil。
与此类似的东西。
SomeCell *cell = (SomeCell*)[self.yourTableView cellForRowAtIndexPath:_yourStoredIndexPath];
cell.someLabel.text = @"Some text";