测试已测试 | ✗ |
语言语言 | Obj-CObjective C |
许可 | MIT |
发布上次发布 | 2017年3月 |
由 Denis Matveev 和 Alexander Gorbunov 维护。
依赖 | |
MAGMatveevReusable | ~> 0.3.5 |
Masonry | ~> 1.0 |
用于简单便捷地操作 UITableView 和 UICollectionView 的框架
本类不直接与 tableView 交互,而应通过 tableManager 来完成。
请注意,MAGTableManager 倾向于使用类似 MAGBaseCell 的单元格(但这并非要求。这只是为了获取 MAGTableManager 及其单元格的特定功能)
0 以项目作为操作单位,而非索引路径!
1 分隔符全宽显示:使用 useSeparatorsZeroInset = YES
2 指定所有分隔符的颜色:separatorsColor = [UIColor myColor]
3 为应用程序中的所有表格设置默认选择颜色:+setDefaultSelectionColor:[UIColor myColor]。然后您可以在任何时候为具体的 MAGTableManager 设置其他值
4 在每个部分的单元格以交替颜色顺序显示 backgroundColor:alternateBackgroundColors = @[myColor1, myColor2, myColor3, etc]
5 数据为空时,在 tableView 上显示 emptyView
setDisplayEmptyViewWhenDataIsEmpty:YES classnameForEmptyView:[MyTableEmptyView class] emptyViewCustomizationBlock:^(UIView *view) {
MyTableEmptyView *v = (MyTableEmptyView *)view;
v.title = @"List is empty";
}
6 如果您想关闭表格底部以避免默认的斑马分隔符,并关闭最后一个单元格的底部,则可以将 useFooterSeparatorViewInsteadOfEmptyTableFooterView 设置为 YES。
7 清除单元格的选中状态一次:clearSelectionOnce = YES 8 禁用用户触摸时的选择更改:changingSelectionByUserTapsDisabled = YES
9 显示具有任何项的单个部分 10 在每个部分中显示具有任何项的多个部分
MAGTableSection *s1 = [MAGTableSection new];
s1.items = @[myItem1, myItem2];
MAGTableSection *s2 = [MAGTableSection new];
s2.items = @[myItem3, myItem4];
sections = @[s1,s2]
在设置项目或部分后,表格将立即重新加载。
11 设置选中项(通过表格中的选中行检测):selectedItems = @[myItem1, myItem2] 获取选中项:[self selectedItems]
12 您可以在任何时候通过 indexPath 或通过单元格快速找到您的项
itemByIndexPath:
itemByCell:
13 您可以找到项在部分的 indexPathsOfItem: inSections: 或了解哪些部分包含项:sectionsContainingItem
14 您可以通过可用方法对项进行操作
makeInsertOperations: animated:completion:
makeReloadOperations: animated: completion:
makeAllItemOccurenciesDeleteOperations: animated: completion:
1) 细胞通过良好的分隔系统扩展,显示在单元格内;2) 忽略(一些低效率的)系统方法来自动计算单元格的高度(不同iOS版本可能不同)。要完成它,您应该:a) 了解“顶视图”是单元格内容视图子view中最小的Y值(这是非常重要的);b) 可以指定底部边距应等于topView y: bottomMarginEqualToTopViewMargin = YES;c) 如果要自定义底部边距,则bottomMarginEqualToTopViewMargin = NO,bottomMargin = 15.0(例如);注意:您可以从xib或代码中设置bottomMarginEqualToTopViewMargin和bottomMargin;d) 在MAGTableManager - heightForItem:中,应返回[baseCell requiredHeight];3) 您可以存储单元格中的任何项目。
1 - method cellClassNamesForNibOrClassRegistering 返回一个数组,包含用于自动注册的特定类名称。例如:InfoCell, UserCell有InfoCell.xib和UserCell.xib;ManagerCell没有ManagerCell.xib;因此,要把它们都作为可重用单元格添加:@[[InfoCell class], [UserCell class], [Manager class]];只需返回它们类的数组
2 - method permanentCellForItem:atIndexPath:;这里应该返回不能重用并且始终可见的单元格。
3 - method cellIdentifierForItem: atIndexPath:;为表格返回cellIdentifier,以便表格知道对于特定indexPath返回哪种单元格;// 添加indexPath,因为不同的部分可以包含相同的项,但以不同的单元格类型显示。为了避免错误行为,您不应该在从-(UITableViewCell *)permanentCellForItem:(id)item atIndexPath:(NSIndexPath *)indexPath方法返回永久单元格时在这里返回单元格的标识符。
4 - method configureCell: withItem: atIndexPath:;如果需要,您可以在这里配置您的单元格。
5 - method configureHeaderView: forSection:;需要,因为您可以在任何时候添加HeaderView
6 - method configureFooterView: forSection:;需要,因为您可以在任何时候添加FooterView