【发布时间】:2017-05-11 12:05:17
【问题描述】:
我设置了 tableview 并希望在数据更改后立即更新 UI。我使用调度程序模拟数据更改。但问题是,该表不会更新。有人能解释一下如何使用 RxSwift 设置一个 tableview 来更新它的数据变化的单元格吗?
@IBOutlet private var tableView: UITableView!
let europeanChocolates: Variable<[Chocolate]> = Variable([])
let disposeBag = DisposeBag()
//MARK: View Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
title = "Chocolate!!!"
setupCellConfiguration()
europeanChocolates.value = Chocolate.ofEurope
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
var choclate = self.europeanChocolates.value[0]
choclate.countryName = "Denmark"
}
}
//MARK: Rx Setup
private func setupCellConfiguration() {
europeanChocolates.asObservable().bindTo(tableView.rx.items(cellIdentifier: ChocolateCell.Identifier, cellType: ChocolateCell.self)) {
row, chocolate, cell in
cell.configureWithChocolate(chocolate: chocolate)
}
.addDisposableTo(disposeBag)
}
【问题讨论】:
标签: ios swift uitableview rx-swift