1

我有一个要求,我需要在 UITableview 的单元格中显示滑块。它基本上是一个下载表格视图,其中音频项目不断下载,下载进度被捕获并显示在表格视图的单元格中。每次下载项目时,我都会收到一个委托方法,并调用 reload table 来更新表视图。这会导致滚动问题,表格不会平滑滚动,因为它将重新加载单元格以进行项目下载。我怎么解决这个问题?

谢谢

4

3 回答 3

2

Accid Bright在这方面绝对走在正确的轨道上,并且可能是一个超出可接受的解决方案。但是,如果您仍然看到性能问题,则可能是单元格在重新加载时仍在做太多工作。我要做的只是更新的值UISlider

NSIndexPath *indexPath = /* index path to the current row to be updated */
MyCustomCell *cell = (id)[self.tableView cellForRowAtIndexPath:indexPath];
[cell.slider setValue:DOWNLOAD_PROGRESS animated:NO];

在不相关的说明中,我建议您查看 usingUIProgressView而不是UISlider因为它更适合显示进度。

于 2013-08-27T14:05:14.610 回答
0

也许

// indexPaths array contains NSIndexPath of you cell with UISlider.
NSArray * indexPaths = @[[NSIndexPath indexPathForRow:1 inSection:0]];
[self.tableView reloadRowsAtIndexPath:indexPaths withRowAnimation:UITableViewRowAnimationNone]; 

能帮你。这允许只更新一些行,而不是所有表。

即使它不能解决问题,最好只更新一行,而不是每秒将所有数据重新加载到表中。

于 2013-08-27T13:56:14.657 回答
0

Swift 4 非常简单的使用方式,只需复制代码即可享受

@objc func sliderUpdate(slider: UISlider){
//MARK:- Add new row in table view
    let indexPath = IndexPath(row: slider.tag, section: 0)
    let cell = self.tableview.cellForRow(at: indexPath) as!  MessagingSenderCell  */MARK:- User user cell name because i am using the MessagingSenderCell for chat and i have use the slider for send a voice message/*
    let cmTime = CMTime(seconds: audioPlayer.duration, preferredTimescale: 1000000)

     let duration : CMTime = cmTime
     var seconds : Float64 = CMTimeGetSeconds(duration)

     self.tableview.beginUpdates()
     cell.slider.maximumValue = Float(seconds)
     self.slidertimer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { timer in
                seconds -= 0.25
                if seconds <= 0 {
                    //print("Go!")
                    self.slidertimer.invalidate()
                    cell.slider.setValue(0, animated: false)
                    self.tablev.endUpdates()
                } else {
                   // print(self.responds)
                   //print("Slider: " + "\(self.sliderr.value)")
                   //print("Player: " + "\(self.audioPlayer.currentTime)")

                    cell.slider.setValue(Float(self.audioPlayer.currentTime), animated: false)
                }
            }


}
于 2019-03-25T08:11:37.030 回答