Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

653
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!