我正在尝试使用自动布局自动调整表格单元格的大小。但似乎 TableView 忽略了高度限制。
我知道“tableView:heightForRowAtIndexPath:”可以做到这一点。
但是如何避免使用高度硬编码?有没有其他方法?
屏幕截图1:
屏幕截图2:
我正在尝试使用自动布局自动调整表格单元格的大小。但似乎 TableView 忽略了高度限制。
我知道“tableView:heightForRowAtIndexPath:”可以做到这一点。
但是如何避免使用高度硬编码?有没有其他方法?
屏幕截图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;
}