RxSwift 3.1 UITableView数据源无法正常工作

时间:2016-12-29 15:23:04

标签: ios swift xcode rx-swift reactivex

我在我的新项目中使用RxSwift 3.1(Galois)通过Carthage我只是尝试使用我在网上和文档中找到的一些示例将数据绑定到UITableView - 其中一个是这个文件: https://github.com/ReactiveX/RxSwift/blob/master/RxExample/RxExample/Examples/SimpleTableViewExample/SimpleTableViewExampleViewController.swift

我的代码现在看起来像这样(我已经尝试将其愚蠢了,因为我想要的工作没有):

class ChooseCityView: UIViewController, UITableViewDelegate {

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {

        super.viewDidLoad()

        let dataSource = Observable.just((0..<20).map { "\($0)" })
        let disposeBag = DisposeBag()

            dataSource.bindTo(tableView.rx.items(cellIdentifier: "CityCell", cellType: UITableViewCell.self)) {
                (row, city, cell) in
                cell.backgroundColor = .white
                cell.textLabel?.text = "test \(city)"
            }.addDisposableTo(disposeBag)

        // Remove empty cells
        tableView.tableFooterView = UIView()

    }
}

仍然,在模拟器中运行应用程序后,这将不会显示任何行。我在tableView上有一个原型单元,名为&#34; CityCell&#34;,类型为Basic。另外,我确保插座与实际的tableView绑定。我能做错什么?或者这是一个错误吗?

提前致谢:)

1 个答案:

答案 0 :(得分:3)

过了一段时间,我找到了解决方案。添加Elixir作为视图控制器的属性。对于您的代码:

disposeBag