提问人:Slackman DevDrive 提问时间:11/26/2021 更新时间:11/26/2021 访问量:38
创建具有每个单元格进度视图的 UITableViewCell 自定义单元格时出现问题
Problem with create UITableViewCell custom cell with progress view each cell
问:
图像 1
向下和向上滚动后。进度条空白 ??
图像 2
每个单元格的自定义单元格,并通过 urlsession 下载。
## custom cell class chattingCustomCell: UITableViewCell { var downloadCustomTask:URLSessionDownloadTask! lazy var progressView : UIProgressView = { let progress = UIProgressView.init() progress.tintColor = .red return progress }() lazy var lbProgressView : UILabel = { let lb = UILabel.init() lb.textAlignment = .center return lb }() func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) { { DispatchQueue.main.async{ if totalBytesExpectedToWrite > 0 { let progress = Float(totalBytesWritten) / Float(totalBytesExpectedToWrite) self.progressView.progress = progress self.lbProgressView.text = "\(Float(totalBytesWritten)) / \(Float(totalBytesExpectedToWrite))" // DispatchQueue.main.async { self.appDelegate.function.loglog(methodDesc: "\(NSStringFromClass(self.classForCoder))", str: "Video download progress : \(progress) -> \(Float(totalBytesWritten))/ \(Float(totalBytesExpectedToWrite))") // self.Progress.progress=progress if(progress == 1) { self.appDelegate.function.loglog(methodDesc: "\(NSStringFromClass(self.classForCoder))", str: "Progress : done") } // } // debugPrint("Progress \(downloadTask) \(progress)") } } } } ..... override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) progressView = UIProgressView.init(frame: CGRect(x: (imageFrame.frame.size.width/2)-(150/2), y: (imageFrame.frame.size.height/2), width: 150, height: 10)) progressView.backgroundColor = UIColor.red progressView.layer.zPosition = 10 progressView.progress = 0 self.imageFrame.addSubview(progressView) lbProgressView = UILabel.init(frame: CGRect(x: (imageFrame.frame.size.width/2)-(150/2), y: (imageFrame.frame.size.height/2)+10, width: 150, height: 10)) lbProgressView.font = UIFont.systemFont(ofSize: 10) lbProgressView.textAlignment = .center self.imageFrame.addSubview(lbProgressView) }
如果不滚动屏幕,它非常适合下载视频,每个单元格都显示进度状态。
向下滚动和向上滚动屏幕时。进度视图是空白的,但 URLSession 仍在下载。
如何修复它。 感谢您的提前。
答: 暂无答案
评论