Ich habe eine Tabellenansicht mit Zellen, die bei Auswahl ein Bild innerhalb der ausgewählten Zelle anzeigt, dieses Bild verschwindet dann, wenn die Zelle erneut ausgewählt wird, und so weiter. Wenn ich eine Senden-Schaltfläche drücke, werden die ausgewählten Zellen gespeichert und die Tabellenansicht wird mit neuen Daten neu geladen. Wenn dies durchgeführt wird, werden alle neuen Daten geladen, aber das ausgewählte Zellenbild bleibt bestehen. Ich habe versucht, tableView.ReloadData() in der Hauptwarteschlange aufzurufen, aber es bleibt bestehen. Das Bild bleibt auch bestehen, wenn ich den Absenden-Knopf mehrmals drücke.Tabellenansicht persistente Zelle Bild nach dem Neuladen
Heres mein Code:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return currentQuestion.answers.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return tableView.frame.height/CGFloat(currentQuestion.answers.count)
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
setSelectedArray()
let cell: AnswersTableViewCell = tableView.dequeueReusableCell(withIdentifier: "answersTableViewCell") as! AnswersTableViewCell
let text = currentQuestion.answers[indexPath.row]
let isAnAnswer = currentQuestion.answerKeys[indexPath.row]
cell.answerTextLabel.text = text
cell.answerView.backgroundColor = UIColor.white.withAlphaComponent(0.5)
cell.contentView.sendSubview(toBack: cell.answerView)
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let cell: AnswersTableViewCell = tableView.cellForRow(at: indexPath) as? AnswersTableViewCell {
if cell.answerImageView.image == nil {
cell.answerImageView.image = UIImage(named: "paw.png")
selected[indexPath.row] = true
} else {
cell.answerImageView.image = nil
selected[indexPath.row] = false
}
}
}
@IBAction func submitButtonWasPressed() {
if questionNumber < questions.count - 1 {
questionNumber += 1
setCurrentQuestion()
self.answersTableView.reloadData()
self.view.setNeedsDisplay()
}
}
Jede Hilfe wäre toll. Danke
erstaunlich, ich habe etwas so ähnlich versucht, aber gescheitert. Vielen Dank! – Wazza