I studied example in a demo to create a UITableView and display cells.
In my opinion, items is a viewModel, I want to request some data over the network using Alamofire or another library. When I get the answer, how can I update the corresponding cell text?
In other words, I want to bind viewModel to cells. When the model data changed, the contents of the cells could be changed automatically.
I have an idea: create an Observable sequence for the contents of the cell (cell binding). When the server response data, it calls the tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top) function. But this does not seem to be grace or a good method.
So, hope some can help me :)
let items = Observable.just([ "First Item", "Second Item", "Third Item" ]) items .bindTo(tableView.rx_itemsWithCellIdentifier("Cell", cellType: UITableViewCell.self)) { (row, element, cell) in cell.textLabel?.text = "\(element) @ row \(row)" /* to do some binding or something else ? */ } .addDisposableTo(disposeBag) tableView .rx_modelSelected(String) .subscribeNext { value in DefaultWireframe.presentAlert("Tapped `\(value)`") } .addDisposableTo(disposeBag)
source share