Swift 在每个单元格单击时快速填充进度条
Swift 在每个单元格单击时快速填充进度条,swift,uitableview,progress-bar,uiprogressview,Swift,Uitableview,Progress Bar,Uiprogressview,tableView中的每个我的单元格都有自己的进度条,该进度条在cellForRowAt方法中填充,工作正常 我的问题是,每当我选择一个单元格时,它的进度条就会刷新 有人知道为什么以及如何预防吗?我认为didSelectRowAt方法不是原因,因为该方法对progressBar没有任何作用 填充进度条的方法: func updateProgressBar(_ cell: TestTableViewCell, level: String) { let cellCards = Float64
tableView
中的每个我的单元格都有自己的进度条,该进度条在cellForRowAt
方法中填充,工作正常我的问题是,每当我选择一个单元格时,它的进度条就会刷新
有人知道为什么以及如何预防吗?我认为
didSelectRowAt
方法不是原因,因为该方法对progressBar没有任何作用
填充进度条的方法:
func updateProgressBar(_ cell: TestTableViewCell, level: String) {
let cellCards = Float64(self.getNumberOfCardsForLevel(level: level))!
let totalCards = Float64(self.totalCards())!
delay(0.3) {
cell.cellProgress.setProgress(Float(cellCards / totalCards), animated: true)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell", for: indexPath) as! TestTableViewCell
cell.accessoryType = .disclosureIndicator;
cell.cellProgress.progress = 0
cell.cellTitle.text = "Test"
cell.numOfCardsInCell.text = getNumberOfCardsForLevel(level: "1")
updateProgressBar(cell, level: "1")
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.tableView.indexPathsForSelectedRows?.forEach { index in
if(self.cellSelectedImage[indexPath.row] == UIImage(named: "imageTwo") ) {
tableView.deselectRow(at: indexPath, animated: false)
self.cellSelectedImage[indexPath.row] = UIImage(named: "imageOne")
}
else {
print("Selected row -> \(index.row)")
if self.cellSelectedImage[indexPath.row] == UIImage(named: "imageTwo") {
self.cellSelectedImage[indexPath.row] = UIImage(named: "imageOne")
}
}
}
tableView.reloadRows(at: [indexPath], with: .automatic)
}
分享你的code@chirag90问题更新共享所有相关代码,包括didSelectForRowAt。正如您提到的,当您单击单元格时,它会被更新。@chirag90已更新,但我认为它没有帮助。在每次单击事件中,您都会重新加载tableview。这将触发tableview委托方法。包括CellForRowAt。当它被触发时,你调用
updateProgressBar(单元格,级别:“1”)
。希望这有帮助?