gpt4 book ai didi

swift - RxTableViewSectionedReloadDataSource

转载 作者:搜寻专家 更新时间:2023-10-31 22:17:50 25 4
gpt4 key购买 nike

这是 RxSwift 中的一个 tableView我无法配置数据源。 RxTableViewSectionedReloadDataSource 似乎缺少参数,尽管这很奇怪,因为我遵循与 official docs 完全相同的代码源。

Xcode error每当我按回车键自动完成关闭。闭包保持空白。

autocomplet not effectiv 我真的不知道如何解决这个问题

  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
}
}

最佳答案

你的代码看起来很好,它可能是评论中提到的版本问题,但你可以通过移动 init 中的配置轻松解决它 像这样:

let dataSource = RxTableViewSectionedReloadDataSource<SectionModel>(
configureCell: { (dataSource, tableView, indexPath, item) -> NewsFeedCell in
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! NewsFeedCell
cell.configure(news: item)
return cell
},
titleForHeaderInSection: { dataSource, index in
return dataSource.sectionModels[index].header
})

其他都一样

关于swift - RxTableViewSectionedReloadDataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51620192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com