Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

650
Vistas
How to animate deleting cell from tableview (rxswift)?

When a user swipe a cell, it becomes possible to delete it. However, the deletion occurs without animation.

Part of code in my ViewController:

override func viewDidLoad() {
        super.viewDidLoad()

        guard let foodCategoryDetailViewModel = foodCategoryDetailViewModel else { return }

        tableView.delegate = nil
        tableView.dataSource = nil

        foodCategoryDetailViewModel.foodsInSelectedCategory
            .bind(to: tableView.rx.items(cellIdentifier: FoodCategoryDetailTableViewCell.cellIdentifier, cellType: FoodCategoryDetailTableViewCell.self))
            { row, food, cell in
                cell.foodCategoryDetailCellViewModel = foodCategoryDetailViewModel.cellViewModel(forRow: row)
            }.disposed(by: disposeBag)

        tableView.rx.itemDeleted.subscribe(onNext: { indexPath in
            foodCategoryDetailViewModel.removeFoodFromApplication(atRow: indexPath.row)
        }).disposed(by: disposeBag)
    }

Part of code in my ViewModel:

class FoodCategoryDetailTableViewViewModel: FoodCategoryDetailTableViewViewModelType {
    var foodsInSelectedCategory: BehaviorRelay<[Food]>

    func removeFoodFromApplication(atRow row: Int) {
        if let food = getFood(atRow: row) {
            foodsInSelectedCategory.remove(at: row)
            //remove from core data   
          CoreDataHelper.sharedInstance.removeFoodFromApplication(foodName: food.name!)
        }
    }

How to animating deleting process from tableView?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

In order to animate the deleting process, you need a datasource that is designed to do that. The default datasource in RxSwift is not.

The most popular library for such a thing is RxDataSources which brings in a full blown multi-section system for animating table and collection views, but if you don't want something that elaborate, you can easily write your own.

Here is an example of a simple animatable datasource for RxSwift that uses DifferenceKit to calculate which cells must be animated on/off: (https://github.com/danielt1263/RxMultiCounter/blob/master/RxMultiCounter/RxExtensions/RxSimpleAnimatableDataSource.swift)

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda