【问题标题】:UITableViewCell of different heights不同高度的UITableViewCell
【发布时间】:2011-06-02 16:36:38
【问题描述】:

我正在尝试使用不同高度的 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;
}

【问题讨论】:

    标签: ios4 uitableview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-06-30
      • 2016-01-25
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 2015-08-29
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      相关资源
      最近更新 更多