Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将进度设置为UITableViewCell元素_Ios_Swift_Uitableview_Rx Swift - Fatal编程技术网

Ios 将进度设置为UITableViewCell元素

Ios 将进度设置为UITableViewCell元素,ios,swift,uitableview,rx-swift,Ios,Swift,Uitableview,Rx Swift,我有一个UITableViewCell,带有自定义UIView和进度条。通过点击cell,应用程序开始使用Alamofire从API加载一些内容。我知道如何获取当前下载的进度,以及如何将其传递给进度视图,但我使用的是RxSwift+领域,当我滚动UITableView单元格时,其进度不会显示。我想在滚动UITableView时显示进度。我尝试将进度存储在单元格的Realm元素变量中,并在单元格中订阅了该变量,但此操作将加载maintrade 这是我的UITableView的数据源 let tab

我有一个UITableViewCell,带有自定义UIView和进度条。通过点击cell,应用程序开始使用Alamofire从API加载一些内容。我知道如何获取当前下载的进度,以及如何将其传递给进度视图,但我使用的是RxSwift+领域,当我滚动UITableView单元格时,其进度不会显示。我想在滚动UITableView时显示进度。我尝试将进度存储在单元格的Realm元素变量中,并在单元格中订阅了该变量,但此操作将加载maintrade

这是我的UITableView的数据源

let tableData: Observable<[Song]> = Observable.combineLatest(loadedData.asObservable(), dbData.asObservable()) { (loadedData, dbData) -> [Song] in
        var newArray = self.currentPlaylist == nil ? loadedData.filter({ !$0.isInvalidated }) : dbData.filter({ !$0.isInvalidated && self.currentPlaylist!.plSongs.contains($0) })

        if self.currentPlaylist == nil {
            _ = dbData.filter({ !$0.isInvalidated }).map({ data in
                if newArray.contains(where: { $0.compoundKey == data.compoundKey && !data.isInvalidated }) {
                    newArray[newArray.index(where: {$0.compoundKey == data.compoundKey && !data.isInvalidated })!] = data
                }
            })
        }
        return newArray.filter({ !$0.isInvalidated })
    }

    tableData
        .bind(to: self.tableView.rx.items(cellIdentifier: "SongCell", cellType: SongTableViewCell.self)) { (_, element, cell) in
            cell.songResponse = element

            cell.selectionStyle = .none
            cell.backgroundColor = .clear
        }
        .disposed(by: bag)
让tableData:Observable=Observable.CombineTest(loadedData.asObservable(),dbData.asObservable()){(loadedData,dbData)->[Song]在
var newArray=self.currentPlaylist==nil?loadedData.filter({!$0.isInvalidated}):dbData.filter({!$0.isInvalidated&&self.currentPlaylist!.plSongs.contains($0)})
如果self.currentPlaylist==nil{
_=dbData.filter({!$0.isInvalidated}).map({data in)
如果newArray.contains(其中:{$0.compoundKey==data.compoundKey&&!data.isInvalidated}){
newArray[newArray.index(其中:{$0.compoundKey==data.compoundKey&&!data.isInvalidated})!]=data
}
})
}
返回newArray.filter({!$0.isInvalidated})
}
表格数据
.bind(到:self.tableView.rx.items(cellIdentifier:“SongCell”,cellType:SongTableViewCell.self)){(\ux,元素,单元格)中的
cell.songResponse=元素
cell.selectionStyle=.none
cell.backgroundColor=.clear
}
.处置(由:袋)
这是UITableView单元格

var songLoadedProgress = Variable<Float?>(nil)
var songResponse: Song? {
    didSet {
        self.layoutCell()
    }
}

func layoutCell() {
    songLoadedProgress.value = songResponse?.songLoadedProgress

            songLoadedProgress.asObservable()
        .bind { (progress) in
            guard let loadingProgress = progress else { return }
            self.downloadView.circleView.setProgress(value: CGFloat(loadingProgress), animationDuration: 0.1)
        }
        .disposed(by: cellBag)
}
var songLoadedProgress=变量(nil)
回答:宋?{
迪塞特{
self.layoutCell()
}
}
func layoutCell(){
songLoadedProgress.value=songResponse?.songLoadedProgress
songLoadedProgress.asObservable()
.bind{(progress)in
guard let loadingProgress=progress else{return}
self.downloadView.circleView.setProgress(值:CGFloat(loadingProgress),animationDuration:0.1)
}
.处置(由:牢房袋)
}

谢谢

您应该将API调用移动到VC,可能是在操作队列中使用委托或其他方式,然后在willDisplayCell上配置单元格,并使用进度和委托进行更新。我同意@SeanLintern88。首先,您应该将api调用移动到视图控制器!