这是 RxSwift 中的 tableView 我无法配置数据源。RxTableViewSectionedReloadDataSource 似乎缺少参数,尽管这很奇怪,因为我遵循与官方文档完全相同的代码源
Xcode 错误 每当我按回车键自动完成关闭时。关闭保持空白。
自动完成无效 我真的不知道如何解决这个问题
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel>()
dataSource?.configureCell = { (ds: RxTableViewSectionedReloadDataSource<SectionOfCustomData>, tv: UITableView, ip: IndexPath, item: Article) -> NewsFeedCell in
let cell = tv.dequeueReusableCell(withIdentifier: "Cell", for: ip) as! NewsFeedCell
cell.configure(news: item)
return cell
}
dataSource?.titleForHeaderInSection = { ds, index in
return ds.sectionModels[index].header
}
let sections = [
SectionOfCustomData(header: "First section", items: self.articles),
SectionOfCustomData(header: "Second section", items: self.articles)
]
guard let dtSource = dataSource else {
return
}
Observable.just(sections)
.bind(to: tableView.rx.items(dataSource: dtSource))
.disposed(by: bag)
}
SectionModel.swift
import Foundation
import RxSwift
import RxCocoa
import RxDataSources
struct SectionOfCustomData {
var header: String
var items: [Item]
}
extension SectionOfCustomData: SectionModelType {
typealias Item = Article
init(original: SectionOfCustomData, items: [Item]) {
self = original
self.items = items
}
}