| 测试测试过的 | ✗ |
| Lang语言 | Obj-CObjective C |
| 许可证 | MIT |
| Released最新发布 | 2015年11月 |
由 Darrarski 维护。
面向对象的UITableViewDataSource和UITableViewDelegate协议代理
对UITableViewDataSource和UITableViewDelegate协议的简单封装,允许通过块或自定义对象轻松配置UITableView内容,这些对象代表部分和行。
DRTableViewManager背后的通用逻辑
完全支持UITableViewDataSource和UITableViewDelegate协议。例如,DRTableViewSection还定义了部分的标题和页脚(以及它们的高度),而DRTableViewRow定义了UITableViewCell高度,didSelect操作等。
此外,DRTableViewManager被设计成允许在iOS 7上使用UITableViewAutomaticDimension单元格高度。可以通过设置DRTableViewManager对象的automaticRowHeightResolvingType属性来配置解决自动单元格高度的行为。DRTableViewAutomaticRowHeightResolvingType有三种可用选项
如果您正在使用需要将preferredMaxLayoutWidth设置为正确布局的UIKit元素,请使用DRTableViewResolveAutomaticRowHeightManually选项以避免在不同iOS版本上出现问题。请参阅示例2以获取更多详细信息。
您可以使用Cocoapods将DRTableViewManager集成到您的项目中。为此,您需要在您的Podfile中添加以下某一行:
对于稳定版本(推荐)
pod 'DRTableViewManager', '~> 1.0.13'
这将创建对版本>= 1.0.13和< 1.1的依赖关系
您还可以从发行页面下载给定版本的zip压缩档。
查看包含的示例项目,或在仓库中的TableViewDemo。
显示基本用法,其中部分和单元格在数组中以静态方式定义。
同样显示了基本用法,但将自动单元格高度配置为基于其内容。适用于iOS 8(使用原生UITableViewAutomaticDimension)和iOS 7(通过AutoLayout计算高度 - 详细信息请参阅源代码)。
示例用法
DRTableViewGenericSectionsController *sectionsController = [[DRTableViewGenericSectionsController alloc] init];
sectionsController.sectionsCountBlock = ^NSInteger {
return 3;
};
sectionsController.sectionAtIndexBlock = ^NSObject <DRTableViewSection> *(NSInteger sectionIndex) {
return [DRTableViewGenericSection createWithBlock:^(DRTableViewGenericSection *section) {
section.tableViewTitleForHeaderInSectionBlock = ^NSString *(UITableView *tableView, NSInteger tableSectionIndex) {
return [NSString stringWithFormat:@"Section %ld", (long)tableSectionIndex];
};
section.tableViewHeightForHeaderInSectionBlock = ^CGFloat(UITableView *tableView, NSInteger tableSectionIndex) {
return 30;
};
section.tableViewNumberOfRowsInSectionBlock = ^NSInteger(UITableView *tableView, NSInteger tableSectionIndex) {
return 3;
};
section.rowAtIndexBlock = ^NSObject <DRTableViewRow> *(NSInteger rowIndex) {
return [DRTableViewGenericRow createWithBlock:^(DRTableViewGenericRow *row) {
row.tableViewHeightForRowAtIndexPathBlock = ^CGFloat(UITableView *tableView, NSIndexPath *indexPath) {
return 44;
};
row.tableViewCellForRowAtIndexPathBlock = ^UITableViewCell *(UITableView *tableView, NSIndexPath *indexPath) {
UITableViewCell *cell = [[UITableViewCell alloc] init];
cell.textLabel.text = [NSString stringWithFormat:@"Row %ld", (long)indexPath.row];
return cell;
};
}];
};
}];
};
_tableViewManager = [[DRTableViewManager alloc] initWithSectionsController:sectionsController];
[_tableViewManager registerInTableView:self.tableView];修复了iOS 9上手动计算行高的问题
为
DRTableViewManager添加了scrollViewDelegate(<UIScrollViewDelegate>)属性
为
DRTableViewManager添加了辅助方法
rowForCell:atIndexPathsectionForFooterHeaderView:atIndex
修复了头文件中的导入语句
DRTableViewManager已更新,添加了sectionAtIndex:和rowAtIndexPath:方法
DRTableViewGenericRow和DRTableViewGenericSection的初始化已调整到常见的模式,构造方法名称从createWithBlock:更改为newWithBlock:
为
DRTableViewManager添加了单元格缓存,对于计算行高时使用的单元格很有用示例更新
为
DRTableViewManager添加了automaticRowHeightResolvingType属性示例更新
为
DRTableViewRow协议添加了tableView:cellForComputingRowHeightAtIndexPath:方法,以支持iOS 7下的UITableViewAutomaticDimension单元格高度为
DRTableViewRow协议添加了tableView:configureCell:forRowAtIndexPath:方法示例更新
部署目标已更改为iOS 7.0,
DRTableViewManager与iOS 7和iOS 8都兼容。添加了示例2,展示了如何实现自动单元格高度,该高度在iOS 8上原生支持,但在iOS 7上需要一些额外代码。
修复了 - 在从
UITableViewDelegate协议中调用tableView:heightForRowAtIndexPath:方法时对DRTableViewRow对象的调用错误
修复了数组中不正确的协议兼容性定义
一些小修复
初始发布,支持iOS 8
MIT许可证(MIT)- 查看包含的LICENSE文件