前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >托管UITableView多样式cell的第三方库ZHTableViewGroup

托管UITableView多样式cell的第三方库ZHTableViewGroup

作者头像
君赏
发布2018-09-07 15:10:49
8150
发布2018-09-07 15:10:49
举报
文章被收录于专栏:君赏技术博客

ZHTableViewGroup

之前遇到过很多复杂的UITableView的结构,里面包含了很多复杂的cell,甚至一个Section包含很多种类的cell。通常在代理

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

返回不同的cell,甚至需要在在

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

写很多判断逻辑的跳转

现在有了这个库,做一些复杂的表格十分的方便,而且十分的简洁。

怎么安装

1.使用cocoapods进行安装

代码语言:javascript
复制
pod 'ZHTableViewGroup'

2.直接下载demo拖拽UITableViewDataSource到工程里面

怎么使用

文件的结构

在例子里面声明一个变量

代码语言:javascript
复制
@property (nonatomic, strong) ZHTableViewDataSource *dataSource;

在UITableView的代理实现这些方法

代码语言:javascript
复制
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataSource.sectionNumber;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    ZHTableViewGroup *group = [self.dataSource groupWithIndex:section];
    return group.rowNumber;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZHTableViewGroup *group = [self.dataSource groupWithIndex:indexPath.section];
    UITableViewCell *cell = [group cellWithIndexPath:indexPath];
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ZHTableViewGroup *group = [self.dataSource groupWithIndex:indexPath.section];
    [group didSelectRowAtIndexPath:indexPath];
}

我们只用在之前初始化数据添加到dataSource

代码语言:javascript
复制
- (void)stepTableViewData {
    ZHTableViewGroup *group = [[ZHTableViewGroup alloc]init];
    ZHTableViewCell *cellOne = [[ZHTableViewCell alloc]initWithTableView:self.homeTableView range:NSMakeRange(0, 6) cellHeight:44 cellClass:[HomeCellStyleOne class] identifier:KHomeCellStyleOneIdentifier];
    cellOne.configCellComplete = ^(UITableViewCell *cell, NSIndexPath *indexPath) {
        HomeCellStyleOne *cellOne = (HomeCellStyleOne *)cell;
        cellOne.textLabel.text = @"One Title";
        cellOne.detailTextLabel.text = @"One Detail";
    };
    cellOne.didSelectRowComplete = ^(UITableViewCell *cell, NSIndexPath *indexPath) {
        NSLog(@"cell->%@,indexPath->%@",cell,indexPath);
    };
    [group addTableViewCell:cellOne];

    ZHTableViewCell *cellTwo = [[ZHTableViewCell alloc]initWithTableView:self.homeTableView range:NSMakeRange(6, 5) cellHeight:44 cellClass:[HomeCellStyleTwo class] identifier:KHomeCellStyleOneIdentifier];
    cellTwo.configCellComplete = ^(UITableViewCell *cell, NSIndexPath *indexPath) {
        HomeCellStyleOne *cellTwo = (HomeCellStyleOne *)cell;
        cellTwo.textLabel.text = @"Two Title";
        cellTwo.detailTextLabel.text = @"Two Detail";
    };
    cellTwo.didSelectRowComplete = ^(UITableViewCell *cell, NSIndexPath *indexPath) {
        NSLog(@"cell->%@,indexPath->%@",cell,indexPath);
    };

    [group addTableViewCell:cellTwo];
    [self.dataSource addTableViewGroup:group];

    [self.homeTableView reloadData];

}

更多的文档请查看Wiki

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016.09.14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ZHTableViewGroup
    • 怎么安装
      • 1.使用cocoapods进行安装
      • 2.直接下载demo拖拽UITableViewDataSource到工程里面
    • 怎么使用
      • 文件的结构
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档