Reputation: 51
I am trying to autoresize table cell with autolayout. But it seems TableView ignores height constraints.
I know that "tableView: heightForRowAtIndexPath:" can do this.
But how to avoid to use height hardcoding ? Is any other ways ?
screen shot 1:
screen shot 2:
Upvotes: 1
Views: 1494
Reputation: 4817
- (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;
}
Upvotes: 2