Skip to content

Commit 2fce283

Browse files
committed
Update README.md
1 parent 125461f commit 2fce283

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

README.md

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ tableViewDataSource.reorderingHandlers.didReorder = { [weak self] transaction, _
4040
}
4141
```
4242

43-
## UITableView Cell and Header/Footer registration
43+
## UITableView Cell Registration
4444

45-
A registration for the table view’s cells and header/footer views similar to `UICollectionView.CellRegistration`.
45+
A registration for the table view’s cells similar to `UICollectionView.CellRegistration`.
4646

4747
Use a cell registration to register table cell views with your table view and configure each cell for display.
4848

@@ -59,11 +59,64 @@ let cellRegistration = UITableView.CellRegistration<UITableViewCell, String> { c
5959
}
6060
```
6161

62-
After you create a cell registration, you pass it in to ``UIKit/UITableView/dequeueConfiguredReusableCell(using:for:item:)``, which you call from your data source’s cell provider.
62+
After you create a cell registration, you pass it in to ``dequeueConfiguredReusableCell(using:for:item:)``, which you call from your data source’s cell provider.
6363

6464
```swift
6565
dataSource = UITableViewDiffableDataSource<Section, String>(tableView: tableView) {
6666
tableView, indexPath, item in
6767
return tableView.dequeueConfiguredReusableCell(using: cellRegistration, for: indexPath, item: item)
6868
}
6969
```
70+
71+
Alternatively you can use the ``UICollectionViewDiffableDataSource`` and ``UITableViewDiffableDataSource`` initializers:
72+
73+
```swift
74+
let dataSource = UITableViewDiffableDataSource(tableView: myTableView, cellRegistration: cellRegistration)
75+
}
76+
```
77+
78+
## UITableView Header/Footer View Registration
79+
80+
A registration for the table view’s header/footer views.
81+
82+
```swift
83+
let sectionViewRegistration = UITableView.SectionViewRegistration<UITableViewHeaderFooterView, String> {
84+
sectionView, indexPath, string in
85+
86+
var configuration = sectionView.defaultContentConfiguration()
87+
configuration.text = string
88+
sectionView.contentConfiguration = configuration
89+
}
90+
```
91+
92+
After you create a section view registration, you pass it in to ``dequeueConfiguredReusableSectionView(using:section:)``, which you call from your data source’s section header view provider.
93+
94+
```swift
95+
dataSource.headerViewProvider = { tableView, section in
96+
return tableView.dequeueConfiguredReusableSectionView(using: sectionViewRegistration, section: section)
97+
}
98+
```
99+
100+
You can also ``applyHeaderViewRegistration()`` and `applyFooterViewRegistration()``:
101+
102+
```swift
103+
dataSource.applyHeaderViewRegistration(sectionViewRegistration)
104+
```
105+
106+
## Diffable DataSource Snapshot Apply Options
107+
108+
Options for applying snapshots to a diffable datasource:
109+
110+
```swift
111+
// Applies the snapshot animated with default animation duration.
112+
dataSource.apply(mySnapshot, .animated)
113+
114+
// Applies the snapshot animated with the specified animation duration.
115+
dataSource.apply(mySnapshot, .animated(duration: 2.0))
116+
117+
// Applies the snapshot non animated.
118+
dataSource.apply(mySnapshot, .withoutAnimation)
119+
120+
// Applies the snapshot using reload data.
121+
dataSource.apply(mySnapshot, .usingReloadData)
122+
```

0 commit comments

Comments
 (0)