0

Each of my cells in tableView has its own progressBar which is being filled in cellForRowAt method and it works fine.
My problem is whenever I select a cell, it's progress bar refreshes filling.
Does anyone have an idea why and how to prevent it? I think didSelectRowAt method is not a reason because that method does nothing with the progressBar.

Method for filling 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)
    }
faris97
  • 402
  • 4
  • 24

0 Answers0