Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

657
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda