iOS 13 个 UITableView select/deselect 问题

iOS 13 UITableView select/deselect problems

我的项目 UITableView 与 ios 12 及更低版本配合使用效果很好,但随着 ios 13 的新更新现在开始出现多个问题。

selection 以我获得最后一个 indexPath 的方式工作,但我在代码中为 selected 行更改背景,现在背景保持 selected我 select 的每一行不仅仅是最后一行,而且我确实设置了我只能 select 一行。

如果我在 indexPath 3 滚动 selected 行,例如有不同的背景,当我滚动时,因为 table 有 90 行,每 10 或 15 行也是 selected,即使我没有 select 它。

最后可能与之相关的是: 我在每一行中都有 s 和我一起做一些动作取决于 行是 selected,当我 select 首先是好的,但是当我 deselect 和 select 另一个第一个在某个地方被记住,我不能 select 接下来,所以那时什么都没有 selected 我不能再 select任何东西。

ios12 及更低版本再次一切正常。

我该如何解决这个问题?

这是我的部分代码:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    //   return self.patientData.arrayNames.count
    return structuredNames.count;
}

// create a cell for each table view row
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell:PatientExercizeCell = self.table.dequeueReusableCell(withIdentifier: "exercizeCell") as! PatientExercizeCell
    cell.cellIndex = indexPath.row

    cell.exercizeName.text = structuredNames[indexPath.row][1]
    cell.appName.text = structuredNames[indexPath.row][0]
    cell.dateOfExercize.text = structuredNames[indexPath.row][2] + " " + structuredNames[indexPath.row][3]

    if(!listOfNotes.isEmpty){
        if(listOfNotes[indexPath.row] != ""){
            cell.noteButton.isHidden = false
            cell.noteButton.tag = indexPath.row
        }else{

            cell.noteButton.isHidden = true
        }
    }

    if(fileHandler.listOfFilesFromDevice.contains(fileNames[indexPath.row]) && patientIsSended && !(leftoverFiles.contains(fileNames[indexPath.row].components(separatedBy: ".t")[0]))){
        cell.deleteButton.isHidden = false
        cell.deleteButton.tag = indexPath.row
    }else{
        cell.deleteButton.isHidden = true
    }

    if(GlobalSession.checkedExercises.contains(indexPath.row)){
        cell.checkMark.isOn = true
    }else{
        cell.checkMark.isOn = false
    }
    return cell
}


// method to run when table view cell is tapped
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    indexPathNumber = indexPath.row
    let selectedCell:UITableViewCell = tableView.cellForRow(at: indexPath)!
    selectedCell.contentView.backgroundColor = Color().blue()


}

Video about difference between ios 12 and 13

试试这些:

  • 禁用多行选择
  • 重置 tableView(_:didDeselectRowAt:)tableView(_:cellForRowAt:)
  • 中的背景颜色

也看看这个类似的问题:

我认为是因为电池的回收行为

我的建议是

  1. 在 tableView(_:didDeselectRowAt:) 中不改变背景颜色,只需将选中的行添加到数组并重新加载数据
  2. 在 tableView(_:cellForRowAt:) 中设置背景颜色取决于所选行的数组