ra1028 / DiffableDataSources

💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.

Home Page:https://ra1028.github.io/DiffableDataSources

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create a table view section header or footer view?

xinsight opened this issue · comments

Checklist

  • Reviewed the README and documents.
  • Searched existing issues for ensure not duplicated.

Expected Behavior

I'd like to show a header or footer view for a section of a table view.

Current Behavior

I'm able to use DiffableDataSources to create sections and add items to the section, and this generates cells, but I cannot figure out how to create a header or a footer view (e.g. a UITableViewHeaderFooterView) for a section of the table view.

For example , if I have:

enum Section {
  case .greetings
}

enum Row {
  case .hello
  case .goodbye
}

func buildSnapshot() {
  let snapshot = DiffableDataSourceSnapshot<Section, AnyHashable>()
  snapshot.appendSections([.greetings])
  snapshot.appendItems(Row.allCases, toSection: .greetings)
  return snapshot
}

lazy var dataSource = TableViewDiffableDataSource<Section, AnyHashable> (tableView: tableView) { tableView, indexPath, item in
  // this is only called for .hello and .goodbye
  // and i can only return a UITableViewCell - not a UITableViewHeaderFooterView
}

## Environment
- version: 0.1.0

- Swift version: 5.0.1

Ah, silly me. The methods that provide headers and footers are part of UITableViewDelegate not data source. So nothing to do with DiffableDataSource.

Please close out your issue @xinsight since it appears resolved.