[英]How can I add sections to my UITableViewCell?
How can I add sections to my UITableViewCell with the Bond framework?如何使用 Bond 框架向我的 UITableViewCell 添加部分?
self.viewModel.items.bind(to: self.tableView) { (item, indexPath, tableView) -> UITableViewCell in
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ListCell.self),
for: indexPath) as! ListCell
cell.item = item[indexPath.row]
return cell
}.dispose(in: self.bag)
Regarding the source code,关于源代码,
if you want to override just a title, you should override this class and implement correspond logic for如果你只想覆盖一个标题,你应该覆盖这个 class 并实现相应的逻辑
open class TableViewBinderDataSource<Changeset: SectionedDataSourceChangeset>: NSObject, UITableViewDataSource
but if you want to implement totally custom view, this is much complicated.但是如果你想实现完全自定义的视图,这就很复杂了。 I don't think that this is possible for this library.
我认为这个图书馆不可能。 the reason is that you should override
UITableViewDelegate
, but it is used in public protocol ReactiveExtensions
that cannot be overridden.原因是您应该覆盖
UITableViewDelegate
,但它用于无法覆盖的public protocol ReactiveExtensions
中。
You must write this class你必须写这个 class
class CustomSection<Changeset: SectionedDataSourceChangeset>: TableViewBinderDataSource<Changeset>, UITableViewDelegate where Changeset.Collection == Array2D <String, ListItemViewModel> {
@objc func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return changeset?.collection[sectionAt: section].metadata
}
and in viewDidload of your ViewController you must call this function.在 ViewController 的 viewDidload 中,您必须调用此 function。
private func setupViewModel() {
let sectionBindingDatSource: CustomSection = CustomSection<TreeChangeset>{ (changeset, indexPath, tableView) -> UITableViewCell in
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: ListCell.self), for: indexPath) as! ListCell
cell.item = changeset.sections[indexPath.section].items[indexPath.row]
return cell
}
self.viewModel.sections.bind(to: self.tableView, using: sectionBindingDatSource)
}
and if you want to override function of TableViewDataSourse and customize section you must set delegate如果要覆盖 TableViewDataSourse 的 function 并自定义部分,则必须设置委托
self.tableView.delegate = sectionBindingDatSource
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.