Problem with create UITableViewCell custom cell with progress view each cell

40 Views Asked by At

Image 1

After scroll down and up. progress bar blank ??

Image 2

  1. Custom cell for each cell and download via 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)
    
    
     }
    
  2. if don't scroll screen it's work perfect for download video each cell with display progress status.

  3. when scroll down and scroll up screen. progress view it's blank but urlsession still downloading.

how to fixed it. Thank you for advance.

0

There are 0 best solutions below