静态动态cell混合使用

本文介绍了UITableView数据源方法的重写实现,包括表格视图的头部和底部标题设置、行高调整、单元格配置等关键功能。通过具体示例展示了如何根据不同条件返回不同的值以实现灵活的表格布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需要重写的方法

#pragma mark - Table view data source

- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    return [super tableView:tableView titleForHeaderInSection:section];

}

- (NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

    return [super tableView:tableView titleForFooterInSection:section];

}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    return NO;

}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

{

    return NO;

}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    return [super tableView:tableView heightForFooterInSection:section];

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.section == 2)

        return 88;

    return [super tableView:tableView heightForRowAtIndexPath:indexPath];

}

- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

{

    return nil;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return [super numberOfSectionsInTableView:tableView];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 2) {

        return self.data.count;

    }

    return [super tableView:tableView numberOfRowsInSection:section];

    

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    if (section == 0) {

        return 20;

    }

    return 30;

}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    return [[UIView alloc] init];

}

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 2) {

        return self.data.count;

    }

    return indexPath.row;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    if (indexPath.section == 2) {

        if (self.noticeBtn.selected) {

            YYOneKindCell *cell = [YYOneKindCell cellWithTableView:tableView];

            cell.item = self.data[indexPath.row];

            return cell;

        }else{

            YYOtherKindCell *cell = [YYOtherKindCell cellWithTableView:tableView];

            cell.item = self.data[indexPath.row];

            return cell;

        }

    }

    return [super tableView:tableView cellForRowAtIndexPath:indexPath];

}


[

调用 didSelectRowAtIndexPath。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     [tableView deselectRowAtIndexPath:indexPath animated:YES];

     
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
}

http://www.itstrike.cn/question/cba84b8a-150b-47f3-833b-bb683617c02c.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值