我是RxSwift的新手,並且需要測試一些樣本。我在RxSwift的幫助下顯示了一些關於uitableview的數據。但是,當我嘗試從tableview中刪除任何項目並重新加載。 Observable數組沒有更新,並且由於在最後一項崩潰時滾動。下面是代碼,請幫助我知道我做錯了什麼。RxSwift中可觀察元素的數組
self.itemArray = NSMutableArray(objects: "First Item","Second Item","Third Item","Fourth Item","Fifth Item","Sixth Item","Seventh Item","Eight Item","Nineth Item","Tenth Item","Eleventh Item","Twelveth Item","Thirtheenth Item","Fourtheenth Item","Fifteenth Item","Sixteenth Item","Seventhenth Item","First Item","Second Item","Third Item","Fourth Item","Fifth Item","Sixth Item","Seventh Item","Eight Item","Nineth Item","Tenth Item","Eleventh Item","Twelveth Item","Thirtheenth Item","Fourtheenth Item","Fifteenth Item","Sixteenth Item","Seventhenth Item")
var seqValue = Observable.just(self.itemArray)
seqValue
.bind(to: rxtableView.rx.items) { (tableView, row, seqValue) in
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")!
cell.textLabel?.text = self.itemArray.object(at: row) as? String
cell.backgroundColor = .clear
return cell
}.disposed(by: disposeBag)
self.rxtableView.rx.itemDeleted
.subscribe(onNext: { [unowned self]indexPath in
self.itemArray.removeObject(at: indexPath.row)
seqValue = Observable.just(self.itemArray)
self.rxtableView.reloadData()
}).addDisposableTo(disposeBag)
我改變了這一行let itemValue = BehaviorSubject.init(value:self.itemArray),它的工作 – Kashif