UITableViewCell имеет прерывистую анимацию вставки / удаления строк - PullRequest
0 голосов
/ 30 марта 2019

В настоящее время я удаляю и вставляю строки на основе содержимого в классе, который называется построителем содержимого. Пример этого можно увидеть ниже.

func stateDidChange(id: String, _ state: Bool) {

    switch id {
    case ConfigureExerciseContentBuilderKeys.accessory.rawValue:
        exerciseProgramming.isAccessory = state

        if state {

            if let customIncrementsItemIndex = self.configureExerciseContentBuilder.getContent().firstIndex(where: { ($0 as? FormLabelTextFieldItem)?.id == ConfigureExerciseContentBuilderKeys.increment.rawValue }),
               let syncedWorkoutsItemIndex = self.configureExerciseContentBuilder.getContent().firstIndex(where: { ($0 as? ExerciseSyncedWorkouts)?.id == ConfigureExerciseContentBuilderKeys.syncedWorkouts.rawValue }) {
                self.configureExerciseContentBuilder = ConfigureExerciseContentBuilder(type: type, exerciseProgramming: exerciseProgramming)

                let incrementsIndexPath = IndexPath(item: customIncrementsItemIndex, section: 0)
                let syncedIndexPath = IndexPath(item: syncedWorkoutsItemIndex, section: 0)
                let spacerIndexPath = IndexPath(item: syncedWorkoutsItemIndex + 1, section: 0)

                self.tableView.beginUpdates()
                self.tableView.deleteRows(at: [incrementsIndexPath, syncedIndexPath, spacerIndexPath], with: .automatic)
                self.tableView.endUpdates()
            }
        } else {

            self.configureExerciseContentBuilder = ConfigureExerciseContentBuilder(type: type, exerciseProgramming: exerciseProgramming)

            if let customIncrementsItemIndex = self.configureExerciseContentBuilder.getContent().firstIndex(where: { ($0 as? FormLabelTextFieldItem)?.id == ConfigureExerciseContentBuilderKeys.increment.rawValue }),
               let syncedWorkoutsItemIndex = self.configureExerciseContentBuilder.getContent().firstIndex(where: { ($0 as? ExerciseSyncedWorkouts)?.id == ConfigureExerciseContentBuilderKeys.syncedWorkouts.rawValue }) {

                let incrementsIndexPath = IndexPath(item: customIncrementsItemIndex, section: 0)
                let syncedIndexPath = IndexPath(item: syncedWorkoutsItemIndex, section: 0)
                let spacerIndexPath = IndexPath(item: syncedWorkoutsItemIndex + 1, section: 0)

                self.tableView.beginUpdates()
                self.tableView.insertRows(at: [incrementsIndexPath, syncedIndexPath, spacerIndexPath], with: .automatic) // Insert into the index of where the accessory row was/is
                self.tableView.endUpdates()
            }
        }

    default:
        break
    }
}

Строки успешно удалены и вставлены в соответствии с логикой выше, и я использовал автоматический параметр, чтобы табличное представление могло справиться с этим наилучшим образом.

Стоит также отметить, что в элементе tableview ячейка используется для элементов внутри них, а также я настроил высоту строки в представлении таблицы как динамическую в зависимости от ее содержимого.

Но по какой-то причине я, кажется, получаю странную прерывистую анимацию, когда я удаляю или вставляю строки для зеленого поля, которое вы можете видеть в прикрепленном видео. У кого-нибудь есть указания / идеи относительно того, почему это может происходить?

Ссылка на видео

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...