Skip to content

Commit a816964

Browse files
committed
Update the README.md because configureCell was added to dataSource init
1 parent 20ec765 commit a816964

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ These are precisely the use cases that RxDataSources helps solve.
4949
With RxDataSources, it is super easy to just write
5050

5151
```swift
52-
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, Int>>()
52+
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, Int>>(configureCell: configureCell)
5353
Observable.just([SectionModel(model: "title", items: [1, 2, 3])])
5454
.bind(to: tableView.rx.items(dataSource: dataSource))
5555
.disposed(by: disposeBag)
@@ -77,38 +77,51 @@ struct SectionOfCustomData {
7777
}
7878
extension SectionOfCustomData: SectionModelType {
7979
typealias Item = CustomData
80-
80+
8181
init(original: SectionOfCustomData, items: [Item]) {
8282
self = original
8383
self.items = items
84-
}
84+
}
8585
}
8686
```
8787

8888
2) Create a dataSource object and pass it your `SectionOfCustomData` type:
89-
```swift
90-
let dataSource = RxTableViewSectionedReloadDataSource<SectionOfCustomData>()
89+
```swift
90+
let dataSource = RxTableViewSectionedReloadDataSource<SectionOfCustomData>(
91+
configureCell: { dataSource, tableView, indexPath, item in
92+
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
93+
cell.textLabel?.text = "Item \(item.anInt): \(item.aString) - \(item.aCGPoint.x):\(item.aCGPoint.y)"
94+
return cell
95+
})
9196
```
9297

9398
3) Customize closures on the dataSource as needed:
94-
- `configureCell` (required)
9599
- `titleForHeaderInSection`
96100
- `titleForFooterInSection`
101+
- `canEditRowAtIndexPath`
102+
- `canMoveRowAtIndexPath`
97103
- etc
98104

99-
```swift
100-
dataSource.configureCell = { (ds: RxTableViewSectionedReloadDataSource<SectionOfCustomData>, tv: UITableView, ip: IndexPath, item: Item) in
101-
let cell = tv.dequeueReusableCell(withIdentifier: "Cell", for: ip)
102-
cell.textLabel?.text = "Item \(item.anInt): \(item.aString) - \(item.aCGPoint.x):\(item.aCGPoint.y)"
103-
return cell
105+
```swift
106+
dataSource.titleForHeaderInSection = { dataSource, index in
107+
return dataSource.sectionModels[index].header
104108
}
105-
dataSource.titleForHeaderInSection = { ds, index in
106-
return ds.sectionModels[index].header
109+
110+
dataSource.titleForFooterInSection = { dataSource, indexPath in
111+
return dataSource.sectionModels[index].footer
112+
}
113+
114+
dataSource.canEditRowAtIndexPath = { dataSource, indexPath in
115+
return true
116+
}
117+
118+
dataSource.canMoveRowAtIndexPath = { dataSource, indexPath in
119+
return true
107120
}
108121
```
109122

110123
4) Define the actual data as an Observable sequence of CustomData objects and bind it to the tableView
111-
```swift
124+
```swift
112125
let sections = [
113126
SectionOfCustomData(header: "First section", items: [CustomData(anInt: 0, aString: "zero", aCGPoint: CGPoint.zero), CustomData(anInt: 1, aString: "one", aCGPoint: CGPoint(x: 1, y: 1)) ]),
114127
SectionOfCustomData(header: "Second section", items: [CustomData(anInt: 2, aString: "two", aCGPoint: CGPoint(x: 2, y: 2)), CustomData(anInt: 3, aString: "three", aCGPoint: CGPoint(x: 3, y: 3)) ])

0 commit comments

Comments
 (0)