HFTableCollectionBindingHelper 1.0.0

HFTableCollectionBindingHelper 1.0.0

测试已测试
语言语言 Obj-CObjective C
许可协议 MIT
发布上次发布2016年8月

Hai Feng Kao维护。



 
依赖项
KVOMutableArray>= 0
WZProtocolInterceptor>= 0
 

  • 作者
  • Hai Feng Kao

UITableView 和 UICollectionView 绑定助手

本项目提供了一些功能函数,可以将可变数组绑定到表格视图或集合视图。它支持单区域或多区域。

注意:集合视图的支持还是 WIP。

用法

KVOMutableArray* someData = [[KVOMutableArray alloc] 
                        initWithMutableArray:[@[@"cell 1", @"cell 2"] mutableCopy]];

HFTableViewBindingHelper* bindingHelper = 
[HFTableViewBindingHelper bindingForTableView:self.tableView 
                                   sourceList:someData 
                            didSelectionBlock:^(id model) 
                                             { NSLog(@"clicked on %@", model); } 
                        templateCellClassName:@"YourCellClass"
                                     isNested:NO];

bindingHelper.delegate = self;
bindingHelper.dataSource = self;

您必须使用 KVOMutableArray 作为可变数组类来通知观察者关于变更事件。关于更多详细信息,请参阅 KVOMutableArray

单元格必须实现 HFBindingViewDelegate 协议。

delegatedataSource 设置是可选的。如果设置了它们,则上述示例中未由绑定助手处理的所有代理方法都将发送到 self

为了支持多区域,应将 isNested 设置为 YES。数组中的每个元素必须是 KVOMutableArray 的类。

KVOMutableArray* firstRow = [[KVOMutableArray alloc] 
                        initWithMutableArray:[@[@"cell 1", @"cell 2"] mutableCopy]];
KVOMutableArray* secondRow = [[KVOMutableArray alloc] 
                        initWithMutableArray:[@[@"cell 1", @"cell 2"] mutableCopy]];
KVOMutableArray* someData = [[KVOMutableArray alloc] initWithMutableArray:[@[firstRow, secondRow] mutableCopy]];

HFTableViewBindingHelper* bindingHelper = 
[HFTableViewBindingHelper bindingForTableView:self.tableView 
                                   sourceList:someData 
                            didSelectionBlock:^(id model) 
                                             { NSLog(@"clicked on %@", model); } 
                        templateCellClassName:@"YourCellClass"
                                     isNested:YES];

安装

HFTableCollectionBindingHelper 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中。

pod "HFTableCollectionBindingHelper"

动机

MVVM (模型-视图-视图模型) 是原始 MVC 架构的一种流行替代品。它将 UI 逻辑从难以测试的控制器移动到可测试的视图模型。MVVM 严重依赖于视图绑定。但是,现有的绑定库(HRTableCollectionBindingHelperCETableViewBinding)不支持具有多个区域的表格视图。此外,它们实现中的表格视图插入和删除动画被禁用,这真的很让我烦恼 :)

贡献

API 从 HRTableCollectionBindingHelper 中引用。

代理转发想法来自 CETableViewBinding

向Rannie和Colin表示衷心的感谢。

要求

需要 iOS 7.0 及以上版本和 ARC。

作者

Hai Feng Kao,[email protected]

贡献

欢迎贡献补丁和其他反馈。

许可证

HFTableCollectionBindingHelper可在MIT许可证下使用。更多信息请参阅LICENSE文件。