![](https://img.haomeiwen.com/i2444456/13ec2f85f79f8805.gif)
展开后显示不同cell只需根据类型判断
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
SectionModel *model = self.dataSource[indexPath.section];
if (model.cellType == SectionCellType1) {
TableViewCell1 *cell = [tableView dequeueReusableCellWithIdentifier:TABLEVIEWCELL1ID];
return cell;
}else if (model.cellType == SectionCellType2){
TableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:TABLEVIEWCELL2ID];
return cell;
}else if (model.cellType == SectionCellType3){
TableViewCell3 *cell = [tableView dequeueReusableCellWithIdentifier:TABLEVIEWCELL3ID];
return cell;
}
TableViewCell1 *cell = [tableView dequeueReusableCellWithIdentifier:TABLEVIEWCELL1ID];
return cell;
}
cell高度自适应
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 50;
可通过autolayout或者Masonry自适应cell高度(前面有文章讲解过)
组头点击事件代理
- (void)selAnSection:(NSInteger)section {
SectionModel * model = self.dataSource[section];
model.isAn =! model.isAn;
// [self.tableView reloadData];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationFade];
}
只需控制模型数据即可控制UI显示内容,只需刷新对应组即可
代码地址
网友评论