GPJDataDrivenTableView is a data-driven way to use UITableView. It is easy to use. It is friendly to evolve with change of requirements.
pod 'GPJDataDrivenTableView'
- download the GPJDataDrivenTableView repository
- copy the GPJDataDrivenTableView sub-folder into your Xcode project
The traditional way is index-driven, we implement the UITableViewDataSource's or UITableViewDelegate's methods base on indexPath:
-tableView:cellForRowAtIndexPath:
-tableView:heightForRowAtIndexPath:
-tableView:didSelectRowAtIndexPath:
This index-driven way based on indexPath results a lot of if-else
code segments, Various cells' code mix together. it is error-prone, hard to evolve with change of requirements.
The core role of data-driven way to use UITableView is GPJDataDrivenTableView class. GPJDataDrivenTableView contains UITableView instance and a dataArray, GPJDataDrivenTableView set itself as UITableView's dataSource and delegate, implement the protocol methods, and covert indexPath to data in dataArray. Finally we can render cell ui and respond to row selection based on data.
This data-driven way is simple, easy to implement each kind of data, cell, and select action separately.