【问题标题】:Custom UITableViewCell built using IB resizing?使用 IB 调整大小构建的自定义 UITableViewCell?
【发布时间】:2011-07-16 23:18:21
【问题描述】:

我已确保我的单元格的自动调整大小掩码允许灵活的宽度,但是当设备旋转时,单元格不会调整大小。

我也验证了tableview被调整了大小,问题直接出在单元格上。

这是我用来创建单元格的代码:

if (cell == nil) {
        // Load the top-level objects from the custom cell XIB.
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MetaTableViewCell" owner:self options:nil];
        // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
        cell = [topLevelObjects objectAtIndex:0];
    }

有人能想到哪里出了问题吗?

使用 IB 创建的单元格是否从未调整大小?

【问题讨论】:

  • 你确定是单元格本身没有被调整大小吗?而不是单元格中的某些内容?
  • 我已经通过从单元格中删除所有内容并显示它来测试这一点。它仍然没有调整大小。
  • 如果单元格中没有任何内容,你怎么知道单元格在哪里?这些是分组风格还是简单风格?据我所知,您永远无法控制表格单元格的宽度;它总是只是桌子本身是什么
  • 我只使用单元格上的标签进行测试,为了澄清,我无法更改宽度。

标签: iphone ipad uitableview autosize


【解决方案1】:

如果是未调整大小的单元格高度,建议您在旋转后修改UITableView委托方法。

-

(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(condition)// has rotation taken place
    // new height
    else
    // old height
    }

请确保在轮换发生时致电[tableView reloadData];

【讨论】:

    【解决方案2】:

    如果我理解你的问题,你想改变 UITableViewCells 的高度,对吧?尝试在 TableView 的委托中添加这一行:

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return *height*;
    }
    

    我遇到了同样的问题。如果您在 IB 中设置大小,您可以在其中放置更多东西,但它仍然会在加载时询问您的委托人的高度。如果你的委托没有实现这个方法,它只会采用默认高度。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多