2017-03-13 22 views
0

我有一個關於如何更新我的自定義表格視圖單元格從Internet上下載文件的進度視圖的問題?如果我重新加載表視圖它需要大量的內存,提高內存在swift語言中更新進度視圖下載自定義表格視圖單元格

tableView.reloadData() 

另外,如果我重新加載只有一個部分,也需要大量的內存,提高內存

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

所以請什麼是最好的在我的自定義表格視圖單元格中更新進度視圖的方法?

下我的自定義表視圖類:

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 
    } 
} 

非常感謝

回答

0

你應該在你的數據源中添加參數相關文件下載進度和更新進步爲主線

if let movieData = movieObject.data { 
    dispatch_get_main_queue().asynchronously() { 
     movieProgreesView.progress = movieData 
     } 
} 
+0

在上面的自定義表格視圖單元格對象中,您是否喜歡您,我如何在從互聯網下載電影期間更新進度視圖?如果我重新加載表視圖它的工作,但它需要使用巨大的內存,我只需要更新進度視圖 – Mustafa

+0

檢查下載進度https://github.com/cmoulton/grokHTMLAndDownloads/tree/progress –

相關問題