Когда установил изменение высоты ForForow, анимация UITableView не работает - PullRequest
0 голосов
/ 06 сентября 2018

Когда установлено изменение высоты, для ForForowAt UITableView анимация не работает, ячейка перепрыгивается.Если выбрана последняя строка и прокрутка вверху, а после касания свернутой строки таблица переместится вверх.Анимация сломана.

enter image description here

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
    tableView.estimatedRowHeight = 300
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return conditionData[indexPath.section].conditions?[indexPath.row].selected ?? false ? 300 : 76
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    conditionData[indexPath.section].conditions?[indexPath.row].selected = true
    tableView.beginUpdates()
    let cell = tableView.cellForRow(at: indexPath) as? ConditionsCell
    cell?.setSelected(true, animated: true)
    tableView.endUpdates()
}

func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
    conditionData[indexPath.section].conditions?[indexPath.row].selected = false
    tableView.beginUpdates()
    let cell = tableView.cellForRow(at: indexPath) as? ConditionsCell
    cell?.setSelected(false, animated: true)
    tableView.endUpdates()
}

1 Ответ

0 голосов
/ 06 сентября 2018

Когда я начал использовать этот метод, анимация выглядит очень хорошо.

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return conditionData[indexPath.section].conditions?[indexPath.row].selected ?? false ? 300 : 76
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...