gpt4 book ai didi

ios4 - 不同高度的UITableViewCell

转载 作者:行者123 更新时间:2023-12-01 04:14:16 25 4
gpt4 key购买 nike

我试图用不同高度的 UITableViewCell 填充 UITableView。我正在返回正确的尺寸

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

  • 看起来框架以某种方式使用了单元格的高度,但出列的单元格仍然具有相同的大小。

    我也尝试过在单个单元格上使用 setFrame: ,但这仍然没有任何效果。我是不是错过了什么

    例如
        - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if (condition 1)
    return 60;
    else if (condition 2)
    return 100;
    return 44;
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"TableViewCell";


    TableViewCell *cell = (TableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
    cell = [[[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    return cell;
    }

    最佳答案

    所以这里是交易。在 TableViewCell 的实现中,我创建了复杂的布局。并且错误地为我有 [self addSubview:] 的 UILabels 之一,而不是 [self.contentView addSubView:] 这是罪魁祸首。

    关于ios4 - 不同高度的UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4581998/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com