【发布时间】:2017-03-09 07:22:34
【问题描述】:
我正在尝试将 RxSwift/RxDataSource 与 TableView 一起使用,但我无法为 configureCell 分配现有函数。代码如下:
import UIKit
import RxSwift
import RxCocoa
import RxDataSources
class BaseTableViewController: UIViewController {
// datasources
let dataSource = RxTableViewSectionedReloadDataSource<TableSectionModel>()
let sections: Variable<[TableSectionModel]> = Variable<[TableSectionModel]>([])
let disposeBag: DisposeBag = DisposeBag()
// components
let tableView: UITableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
setupUI()
setDataSource()
}
func setupUI() {
attachViews()
}
func setDataSource() {
tableView.delegate = nil
tableView.dataSource = nil
sections.asObservable()
.bindTo(tableView.rx.items(dataSource: dataSource))
.addDisposableTo(disposeBag)
dataSource.configureCell = cell
sectionHeader()
}
func cell(ds: TableViewSectionedDataSource<TableSectionModel>, tableView: UITableView, indexPath: IndexPath, item: TableSectionModel.Item) -> UITableViewCell! {
return UITableViewCell()
}
func sectionHeader() {
}
}
Xcode 抛出以下错误:
/Users/.../BaseTableViewController.swift:39:36:无法分配类型“(TableViewSectionedDataSource,UITableView,IndexPath,TableSectionModel.Item)-> UITableViewCell!”的值输入'(TableViewSectionedDataSource, UITableView, IndexPath, TableSectionModel.Item) -> UITableViewCell!'
错误在行抛出
dataSource.configureCell = 单元格
你有什么想法吗?
谢谢
【问题讨论】:
-
将 dataSource 和 section 对象放入 ViewModel :)
标签: ios swift uitableview rx-swift rxdatasources