Anforderung;Swift tableView.reloadRows Löschen von Zellen
Ich habe eine statische UITableView
und ich versuche, eine pickerview
zu öffnen, wenn eine der Zellen angeklickt wird. Ich ändere die Größe mit heightForRowAt
so, wenn der cell
angeklickt wird, muss ich reload
es so, dass die Größe ändert. Wenn ich reloadData()
verwenden es funktioniert perfekt (Ich möchte reloadRows
verwenden, so kann ich Animation hinzufügen)
Ausgabe:
wenn ich reloadRows(at..., with: .automatic)
die Zeilen versuchen einfach verschwinden. Wenn ich reloadRows
in viewWillAppear
nichts ändert, verschwindet die Zeile nicht.
Code:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath)
if colorCelllExpandedIndex != nil{
let prev = colorCelllExpandedIndex
colorCelllExpandedIndex = nil
tableView.reloadRows(at: [prev!], with: .automatic)
//tableView.reloadData()
} else {
colorCelllExpandedIndex = indexPath
colorCell.frame.size.height = CGFloat(colorCellExpandedHeight)
tableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic)
}
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath == colorCelllExpandedIndex {
return CGFloat(colorCellExpandedHeight)
} else {
if indexPath.row == 1 {
return CGFloat(colorCellRegularHeight)
}
return UITableViewAutomaticDimension
}
}
Bildschirmbilder: