RxSwift实现TableView数据绑定三部曲

RxSwift实现TableView数据绑定三部曲,第1张

var dataList = BehaviorSubject(value: [SectionModel]())

//1.tableView创建数据源

let dataSource = RxTableViewSectionedReloadDataSource>(configureCell:{

            _, tableView,indexPath,element in

                let cell: ServiceRxImageCell = tableView.dequeueReusableCell(withIdentifier:                         "ServiceRxImageCell") as! ServiceRxImageCell

                if element is Detail {

                    cell.viewModel = element as? Detail

                }

                return cell

}

})

//2.绑定数据

dataList.asObserver().bind(to: tableView.rx.items(dataSource: dataSource)).disposed(by: disposeBag)

//3.初始化显示数组

let sectionModel = SectionModel.init(model: "", items: array)

dataList.onNext([sectionModel])

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/990447.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存