ALTableKit
数据驱动的UITableView框架,用于构建快速低耦合的tableview,类似IGList CollectionView框架。
用作IGList已经有一段时间了,确实很好用。但发现将tableview全部替换为collectionview成本很高,而且有些情况下collectionview不能完全替代tableview,因此编写了ALTableKit。
特性
-
自动根据cell和identifier注册cell,通过context直接重用(再也不用担心忘记注册cell而闪退了)
-
将TableView的delegate和dataSource分发到不同的Section Controller降低代码耦合
-
通过section controller可以自动缓存table view cell高度
-
通过section controller可以编辑当前section中的cell (插入、删除、重新加载)
-
便于每个section controller进行单元测试
-
可以将复杂的Complex Section Controller拆分成多个Section Provider降低耦合、简化逻辑
-
-
如果cell 1和cell 2根据数据的不同可能存在或不存在,这时候就会有关于cell 4、5、6的位置在哪个位置之类的很多逻辑判断
现在可以使用section controller将这个section拆分成多个section provider
每个section provider单独维护cell的高度、个数、cell和点击事件等,如下:
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| cell 0 | | cell 0 | |
- - - - - - - - - provier 0 - - - - - - - - |
| cell 1 | | cell 1 | |
- - - - - - - - - - - - - - - - - - - - - - - - - - |
| cell 2 | provier 1 | cell 0 | |
- - - - - - - - - - - - - - - - - - - - - - - - - - section controller 0 |
| cell 4 | | cell 0 | |
- - - - - - - - - - - - - - - - - |
| cell 5 | provier 2 | cell 1 | |
- - - - - - - - - - - - - - - - - |
| cell 6 | | cell 2 | |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
安装
CocoaPods
# use_frameworks! is needed for swift projects
use_frameworks!
pod 'ALTableKit', '~>1.1.7'
Carthage
github "wanyawan/ALTableKit" ~>1.1.7
如何使用
演示
ALTableKitDemo项目。
需求
- Xcode 9.0+
- iOS 8.0+
许可证
ALTableKit
遵循MIT许可证。