ra1028 / DiffableDataSources

💾 A library for backporting UITableView/UICollectionViewDiffableDataSource.
https://ra1028.github.io/DiffableDataSources
Apache License 2.0
849 stars 68 forks source link

Create a table view section header or footer view? #8

Closed xinsight closed 4 years ago

xinsight commented 4 years ago

Checklist

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
xinsight commented 4 years ago

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

iwasrobbed-ks commented 4 years ago

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