У меня проблема в том, что
Я использую табличное представление в приложении и хочу, чтобы рядом с каждой выбранной строкой создавалась галочка.Но галочка также генерируется в строках других разделов, за исключением строки в разделе, где страница прокручивается вниз.Однако, когда я печатаю ячейку, по которой щелкнули, результат будет правильным.
Это мой код для создания галочки:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
let row = indexPath.row
let indexpath = NSIndexPath(row: indexPath.row, section: indexPath.section)
let currentCell = tableView.cellForRow(at: indexpath as IndexPath) as! UITableViewCell
currentCell.backgroundColor = UIColor.gray
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
for organ in self.dataSource.organs {
if(organ.name == organName) {
for sympton in organ.symptonList {
if (sympton.name == self.symptonName ){
self.symptonList.append(sympton.questionList[indexPath.section].question + " " + sympton.questionList[indexPath.section].answerList[row].lowercased())
print("*******")
print(sympton.questionList[indexPath.section].question + " " + sympton.questionList[indexPath.section].answerList[row].lowercased())
}
}
}
}
}
Мой метод cellForRowAt:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath as IndexPath)
let row = indexPath.row
for organ in self.dataSource.organs {
if(organ.name == organName) {
for sympton in organ.symptonList {
if(sympton.name == symptonName) {
cell.textLabel?.text = sympton.questionList[indexPath.section].answerList[row]
}
}
}
}
return cell
}
Это очень полезно для меня, если у вас есть какие-либо предложения.