美文网首页iOS开发
TableView列表展开不同cell

TableView列表展开不同cell

作者: 超级卡布达 | 来源:发表于2019-05-31 00:56 被阅读0次
line.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显示内容,只需刷新对应组即可
代码地址

相关文章

网友评论

    本文标题:TableView列表展开不同cell

    本文链接:https://www.haomeiwen.com/subject/qrritctx.html