@@ -49,7 +49,7 @@ These are precisely the use cases that RxDataSources helps solve.
49
49
With RxDataSources, it is super easy to just write
50
50
51
51
``` swift
52
- let dataSource = RxTableViewSectionedReloadDataSource< SectionModel< String , Int >> ()
52
+ let dataSource = RxTableViewSectionedReloadDataSource< SectionModel< String , Int >> (configureCell : configureCell )
53
53
Observable.just ([SectionModel (model : " title" , items : [1 , 2 , 3 ])])
54
54
.bind (to : tableView.rx .items (dataSource : dataSource))
55
55
.disposed (by : disposeBag)
@@ -77,38 +77,49 @@ struct SectionOfCustomData {
77
77
}
78
78
extension SectionOfCustomData : SectionModelType {
79
79
typealias Item = CustomData
80
-
80
+
81
81
init (original : SectionOfCustomData, items : [Item]) {
82
82
self = original
83
83
self .items = items
84
- }
84
+ }
85
85
}
86
86
```
87
87
88
88
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
+ })
91
96
```
92
97
93
98
3 ) Customize closures on the dataSource as needed:
94
- - ` configureCell ` (required)
95
99
- ` titleForHeaderInSection `
96
100
- ` titleForFooterInSection `
97
101
- etc
98
102
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
103
+ ``` swift
104
+ dataSource.titleForHeaderInSection = { dataSource, index in
105
+ return dataSource.sectionModels [index].header
104
106
}
105
- dataSource.titleForHeaderInSection = { ds, index in
106
- return ds.sectionModels [index].header
107
+
108
+ dataSource.titleForFooterInSection = { dataSource, indexPath in
109
+ return dataSource.sectionModels [index].footer
110
+ }
111
+
112
+ dataSource.canEditRowAtIndexPath = { dataSource, indexPath in
113
+ return true
114
+ }
115
+
116
+ dataSource.canMoveRowAtIndexPath = { dataSource, indexPath in
117
+ return true
107
118
}
108
119
```
109
120
110
121
4 ) Define the actual data as an Observable sequence of CustomData objects and bind it to the tableView
111
- ``` swift
122
+ ``` swift
112
123
let sections = [
113
124
SectionOfCustomData (header : " First section" , items : [CustomData (anInt : 0 , aString : " zero" , aCGPoint : CGPoint.zero ), CustomData (anInt : 1 , aString : " one" , aCGPoint : CGPoint (x : 1 , y : 1 )) ]),
114
125
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