【问题标题】:update progress view download within custom table view cell in swift language以swift语言在自定义表格视图单元格中更新进度视图下载
【发布时间】:2017-03-13 09:19:01
【问题描述】:

我有一个问题,关于如何在从 Internet 下载文件的自定义表格视图单元格中更新我的进度视图?如果我重新加载表格视图,它会占用大量内存并增加内存

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

非常感谢

【问题讨论】:

    标签: swift3 tableview tableviewcell uiprogressview


    【解决方案1】:

    您应该在数据源中添加一个与主线程中的文件下载进度和更新进度相关的参数

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

    【讨论】:

    • 我在上面的自定义表格视图单元格对象中像你一样,我如何在从互联网下载电影的过程中更新进度视图?如果我重新加载表格视图,它可以工作,但需要使用巨大的内存,我只需要更新进度视图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多