tableview group cell xib创建,点击刷新高度+2的问题

本文探讨了一个关于UITableView的问题,即每次点击cell后行高会增加2的现象。通过展示具体的代码片段,作者尝试重现并分析这一奇怪的行为。
cell我是用xib创建的,然后每次在heightForRowAtIndexPath 方法里面,直接返回cell的高度
然后点击,我直接 reloadData
发现在group下,每次点击,行高的高度都会+2

原因还没有找到,很奇怪



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [testTableview reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    switch (indexPath.section) {
        case 0:
        {
            NSLog(@"%f",cellTest.frame.size.height);
            return cellTest.frame.size.height;
        }
            break;
        case 1:
        {
            NSLog(@"%f",cellText2.frame.size.height);
            return cellText2.frame.size.height;
        }
            break;
            
        default:
            break;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return cellTest;
    }else{
        return cellText2;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值