1

我正在尝试使用自动布局自动调整表格单元格的大小。但似乎 TableView 忽略了高度限制。

我知道“tableView:heightForRowAtIndexPath:”可以做到这一点。

但是如何避免使用高度硬编码?有没有其他方法?

屏幕截图1:

https://dl.dropbox.com/s/3spak2koe2s6jif/1.png

屏幕截图2:

[https://dl.dropbox.com/s/dnumxqv28bjh939/2.png]2

4

1 回答 1

2
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static UITableViewCell *cell;
    if (cell == nil) {
        cell = [tableView dequeueReusableCellWithIdentifier: @"YourCell"];
    }
    [self configureCell:cell forIndexPath:indexPath]; // making text assignment and so on
    return [cell.contentView systemLayoutSizeFittingSize: UILayoutFittingCompressedSize].height + 1.0f;
}
于 2013-10-14T05:42:26.743 回答