-
Notifications
You must be signed in to change notification settings - Fork 12
快速继承使用
君赏 edited this page Sep 14, 2016
·
2 revisions
目前可以采用两种集成到项目的方法
pod 'ZHTableViewGroup'前往https://github.com/15038777234/ZHTableViewGroup首页
点击下载的按钮

下载工程的源文件保存在本地

拖拽工程的文件夹ZHTableViewSource到工程里面
配置完成
ZHTableViewDataSource类的对象托管整个UITableView的数据源,我们需要创建一个属性或者全局变量
我们创建一个属性名称为dataSource
@property (nonatomic, strong) ZHTableViewDataSource *dataSource;我们假设当前的UITableView有一个section并且当前的section包含两种cell,前是个是第一种cell,后面的五个是第二种cell
我们首先创建一个ZHTableViewGroup对象托管一个section
ZHTableViewGroup *group = [[ZHTableViewGroup alloc]init];创建第一种cell的托管对象ZHTableViewCell
ZHTableViewCell *cellOne = [[ZHTableViewCell alloc]initWithTableView:self.homeTableView range:NSMakeRange(0, 6) cellHeight:44 cellClass:[HomeCellStyleOne class] identifier:KHomeCellStyleOneIdentifier];创建的api文档请参考api Wiki部分
创建前十个cell配置样式block的回调
cellOne.configCellComplete = ^(UITableViewCell *cell, NSIndexPath *indexPath) {
HomeCellStyleOne *cellOne = (HomeCellStyleOne *)cell;
cellOne.textLabel.text = @"One Title";
cellOne.detailTextLabel.text = @"One Detail";
};创建前十个cell点击方法的回掉
cellOne.didSelectRowComplete = ^(UITableViewCell *cell, NSIndexPath *indexPath) {
};后面的五个cell可以参考上面的代码,可以看源码得到一些提示
把托管的cell对象存在group对象里面
[group addTableViewCell:cellOne];把我们的group对象存在dataSource对象里面
[self.dataSource addTableViewGroup:group];刷新表格
[self.homeTableView reloadData];#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];
}