Swift: Как я могу группировать или клубить загрузки элементов в одну ячейку tableView - PullRequest
0 голосов
/ 05 февраля 2020

Может быть, я не могу правильно объяснить это, я реализовал механизм загрузки файлов. Загрузка файлов отлично, даже URLSession и индикатор выполнения работают эффективно. Я использую TableView для отображения. Изображение также прилагается.

Проблема - я хочу клубиться или объединиться в одну ячейку загрузки. Одно AppName содержит 11 файлов, поэтому ячейка отображается 11 раз. Но я хочу показать его отображение только один раз, и прогресс продолжается до конца файлов. Вместо 11 ячеек он должен отображать 1 ячейку.

Как мне этого добиться? У меня нет идеи для этого?

fileprivate var fileDownLoadDataArray:[DownLoadData] = []

func detailData(AppId: Int, AppName: String){

        if let url = Bundle.main.url(forResource: "AppointmentDetail", withExtension: "json") {
            do {

                let data = try Data(contentsOf: url)
                let decoder = JSONDecoder()
                let jsonData = try decoder.decode(AppointmentDetail.self, from: data)
                self.AppDetailData = jsonData

                for param in AppDetailData?.sectionList ?? [] {
                    for item in param.items! {

                        if item.actionType == 2 {
                            let filename = item.actionUrl ?? ""

                            let data = DownLoadData(with: AppName, and: item.actionUrl ?? "")
                            fileDownLoadDataArray.append(data)
                        }
                    }
                }

            } catch {
                print("error:\(error)")
            }
        }

    }

Класс NSObject


class DownLoadData: NSObject {
    var fileTitle: String = ""
    var downloadSource: String = ""
    var downloadTask: URLSessionDownloadTask?
    var taskResumeData: Data?
    var downloadProgress: Float = 0.0
    var isDownloading: Bool = false
    var isDownloadComplete: Bool = false
    var taskIdentifier: Int = 0
    var groupDownloadON:Bool = false
    var groupStopDownloadON:Bool = false

    init(with title:String, and source:String){
        self.fileTitle = title
        self.downloadSource = source
        super.init()

    }

TableView DataSource:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return fileDownLoadDataArray.count 
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ChildTableViewCell", for: indexPath) as! ChildTableViewCell

        let downloadData = fileDownLoadDataArray[indexPath.row]
        cell.configureCell(with: downloadData)
        cell.cellDelegate = self

        return cell
    }

Изображение:

Download

1 Ответ

1 голос
/ 06 февраля 2020

The result you want

log file for download file

Вам нужно заменить код.

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.Appdata!.count //Appdata?.count ?? 0
}

В cellForRowAt ..

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "ChildTableViewCell", for: indexPath) as! ChildTableViewCell
    //let dic = Appdata?[indexPath.row]

    //cell.fileNameLabel.text = dic?.projectName

    let downloadData = fileDownLoadDataArray[indexPath.row]

    let mainProject = self.Appdata![indexPath.row]
    print(mainProject.projectName as Any)

    cell.configureCell(with: downloadData , projectName: mainProject)
    cell.cellDelegate = self

    return cell
}

В ConfigureCell

 func configureCell(with downloadInfo:DownLoadData, projectName:Appointment){

    // Set the download info into the cell
    self.downloadData = downloadInfo

    fileNameLabel.text = projectName.projectName
    if self.downloadData.groupDownloadON {
        startOrPauseDownload()
        // reset flag
        self.downloadData.groupDownloadON = false
    }
    if self.downloadData.groupStopDownloadON{

        stopDownload()
        self.downloadData.groupStopDownloadON = false
    }
    updateView()


}

Надеюсь, что вы ищете.

...