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

464
Views
RxSwift Swift - Select/Deselect multiple rows in tableView

I can select rows in tableView.rx but I'm wonder how to get array of final selection. I mean the result array of selecting some rows and then deselecting some rows.

Here's my code:

 Observable.zip(tableView.rx.modelSelected(Country.self), tableView.rx.itemSelected).subscribe(onNext: { (selectedCountry, indexPath) in
            print("2 selected Country is \(selectedCountry) and indexPath is \(indexPath.row)")
            self.selectedCountries.append(selectedCountry)

I want also see selected rows as marked.

I appreciate for your helping. thanks

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

First you have to use this:

tableView.allowsMultipleSelection = true

Then you could use these to do what ever you want:

  let selectedItems = tableView.rx.modelSelected(Country.self).subscribe { item in
        print("selected: \(item)")
        print("selected rows: \(self.tableView.indexPathsForSelectedRows)")
  }
  let deselectedItems = tableView.rx.modelDeselected(Country.self).subscribe { item in
        print("deselected: \(item)")
  }
over 4 years ago · Santiago Trujillo Report

0

This will produce an Observable array of indexPaths:

    tableView.allowsMultipleSelection = true
    
    let selectedItems = Observable.merge(
        tableView.rx.itemSelected.asObservable(),
        tableView.rx.itemDeselected.asObservable()
    )
        .flatMap { [tableView] _ in
            Observable.just(tableView.indexPathsForSelectedRows ?? [])
        }
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!