ZDTableViewBinding
简介:
ZDTableViewBinding
是利用ReactiveCocoa
来自动分发tableView
的数据、计算高度并缓存的工具,支持header
和footer
。
ZDTableViewBinding 使用方法:
主要的是一个实例方法和一个类方法
+ (instancetype)bindingHelperForTableView:(__kindof UITableView *)tableView
multiSection:(BOOL)multiSection
dataSourceSignal:(__kindof RACSignal *)dataSourceSignal
cellCommand:(nullable RACCommand *)cellCommand
headerFooterCommand:(nullable RACCommand *)headerFooterCommand
在传递参数之前,需要把cell
和section
包装成cellViewModel
、sectionViewModel
,监听source数据,然后将sourceSignal
传递给ZDTableViewBindingHelper
,剩下的就不用担心了。
cell和section中的控件的响应事件将通过外部的command
进行操作,比如,当footer
上的
- (IBAction)bottomButtonAction:(UIButton *)sender
{
NSLog(@"tap footer button");
[self.headerFooterCommand execute:RACTuplePack(sender, self.sectionModel)];
}
然后bindingHelper
对应的command
将被执行,你可以在tuple
中通过设置指定的key来判断是哪个控件传递了事件,然后再进行相应的处理操作。
如果想单独执行tableViewDelegate
的某个方法,则需要设置delegate
,并实现相关协议。
使用CocoaPods进行安装
请将以下行添加到Podfile。
pod 'ZDTableViewBinding'
然后,运行以下命令
$ pod install
许可证
ZDTableViewBinding 采用 MIT 许可证。更多详细信息请参见 LICENSE 文件。