如何使用单元格类型方法绑定到rx tableView?

问题描述

我有一些使用tableView绑定到rx的测试数据,但是我得到的只是空白的cell

我的cell type看起来像这样:

class StaticSupportTableViewCellviewmodel {
    var myString: String
    init(myString: String) {
        self.myString = myString
    }
}

class StaticSupportTableViewCell: UITableViewCell {
    @IBOutlet var myStringLabel: UILabel!

    static let identifier: String = "StaticSupportTableViewCell"
    
    var viewmodel: StaticSupportTableViewCellviewmodel? {
        didSet {
            myStringLabel.text = viewmodel?.myString
        }
    }
}

viewmodel中,我接受relay的数据

var staticContent = BehaviorRelay<[StaticSupportTableViewCellviewmodel]>(value: [])
    
staticContent.accept([StaticSupportTableViewCellviewmodel(myString: "TESTING")])

然后在viewController中,将数据绑定到tableView上,如下所示:

viewmodel.staticContent.bind(to: tableView.rx.items(cellIdentifier: StaticSupportTableViewCell.identifier,cellType: StaticSupportTableViewCell.self)) { row,data,cell in
    cell.viewmodel = data
}.disposed(by: disposeBag)

不要以为我完全掌握了它应该如何工作,所以我确定这里有些问题,但是我无法发现它们是什么。我知道绑定到tableVIew时还有其他更简单的方法可以使用,但是我需要使用items(cellIdentifier:cellType。当我接受relay的数据时,我感到有些不安。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)