0

i have an question about how can i update my progress view in my custom table view cell which is download file from the internet ? if i reload the table view it take huge memory and increasing the memory

tableView.reloadData()

also if i reload the only one section it also take huge memory and increase memory

 tableView.reloadSections([0], with: .none)

so please what is the best way to update progress view within my custom table view cell?

the following my custom table view class :

import UIKit

class DownloadingTableViewCell: UITableViewCell {

    @IBOutlet weak var movieDeleteButton: UIButton!
    @IBOutlet weak var movieImageView: UIImageView!
    @IBOutlet weak var movieNameLabel: UILabel!
    @IBOutlet weak var movieProgreesView: UIProgressView!
    @IBOutlet weak var movieSizeLabel: UILabel!

    weak var movieObject:DownloadVideo? {
        didSet {
            updateUI()
        }
    }

    func updateUI() {

        movieImageView.image = nil
        movieNameLabel.text = nil
        movieSizeLabel.text = nil
        movieProgreesView.progress = 0.0

        if let movieObject = movieObject {

            movieImageView.image = UIImage(named: "movie")
            movieNameLabel.text = movieObject.videoName

             // set the label size file
            if movieObject.totalData != nil {
            let totalSize = ByteCountFormatter.string(fromByteCount:movieObject.totalData!, countStyle: .binary)
            movieSizeLabel.text = String(format: "%.1f%% of %@", (movieObject.data)! * 100 ,totalSize)
            }
            /////////////////////////

            if let movieData = movieObject.data {
               movieProgreesView.progress = movieData
            }

        }// end the fetch object 
    }
}

thanks a lot

Mustafa
  • 253
  • 1
  • 7
  • 15

1 Answers1

0

You should add a parameter in your data source related to file downloading progress and update progress in main thread

 if let movieData = movieObject.data {
    dispatch_get_main_queue().asynchronously() {
         movieProgreesView.progress = movieData
      }
 }
Abdelahad Darwish
  • 5,969
  • 1
  • 17
  • 35
  • am do it like you in the custom table view cell object above , how can i update the progress view during i download the movie from the internet? if i reload the table view it's work but it's take using huge memory i need only update the progress view – Mustafa Mar 14 '17 at 09:05
  • check this progress downloading https://github.com/cmoulton/grokHTMLAndDownloads/tree/progress – Abdelahad Darwish Mar 14 '17 at 09:36