@@ -49,7 +49,7 @@ These are precisely the use cases that RxDataSources helps solve.
4949With 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 )
5353Observable.just ([SectionModel (model : " title" , items : [1 , 2 , 3 ])])
5454 .bind (to : tableView.rx .items (dataSource : dataSource))
5555 .disposed (by : disposeBag)
@@ -77,38 +77,49 @@ struct SectionOfCustomData {
7777}
7878extension 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
88882 ) 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
93983 ) Customize closures on the dataSource as needed:
94- - ` configureCell ` (required)
9599- ` titleForHeaderInSection `
96100- ` titleForFooterInSection `
97101- etc
98102
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
104106}
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
107118}
108119```
109120
1101214 ) Define the actual data as an Observable sequence of CustomData objects and bind it to the tableView
111- ``` swift
122+ ``` swift
112123let sections = [
113124 SectionOfCustomData (header : " First section" , items : [CustomData (anInt : 0 , aString : " zero" , aCGPoint : CGPoint.zero ), CustomData (anInt : 1 , aString : " one" , aCGPoint : CGPoint (x : 1 , y : 1 )) ]),
114125 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