[英]RxSwift Swift - Select/Deselect multiple rows in tableView
我可以在 tableView.rx 中選擇行,但我想知道如何獲得最終選擇的數組。 我的意思是選擇一些行然后取消選擇一些行的結果數組。
這是我的代碼:
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)
這將產生一個可觀察的 indexPaths 數組:
tableView.allowsMultipleSelection = true
let selectedItems = Observable.merge(
tableView.rx.itemSelected.asObservable(),
tableView.rx.itemDeselected.asObservable()
)
.flatMap { [tableView] _ in
Observable.just(tableView.indexPathsForSelectedRows ?? [])
}
首先你必須使用這個:
tableView.allowsMultipleSelection = true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.