简体   繁体   English

如何将部分添加到我的 UITableViewCell?

[英]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.

相关问题 如何在UITableViewCell中的4个标签上添加约束 - How can I add constraints to 4 labels in a UITableViewCell 如何在Swift 3中将UIButton添加到UITableViewCell中? - How do I add a UIButton into my UITableViewCell in Swift 3? 如何访问容器中各部分的行? - How can I access the rows in sections in my container? 如何在UITableViewCell内添加交互式视图控制器? - How can I add an interactive view controller inside of a UITableViewCell? 如何将UITextField或UITextView添加到UItableViewCell并编辑内容? - How can I add a UITextField or a UITextView to a UItableViewCell and edit the content? 当我有多个部分时,如何以数字0开头UITableView部分? - How can i start my UITableView section with number 0 when i have multiple sections? 如果我使用的是 SnapshotListener,如何在我的 TableView 中为行和节的删除设置动画? - How can I animate the deletion of Rows and Sections in my TableView if I'm using a SnapshotListener? 如何在UITableViewCell中的UIStackView中添加UIView? - How do I add a UIView to a UIStackView in a UITableViewCell? 如何将UITextView添加到此UITableViewCell? - How do I add a UITextView to this UITableViewCell? 创建自定义UITableViewCell后,如何覆盖UITableViewCell? - How can I overwrite a UITableViewCell after its creation with a custom UITableViewCell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM