I have the following setup: UITableView with custom UITableViewCell implementation. In each cell I have a UILabel and a UIButton. When the table is first displayed, in each of the cells, the UILabel has the number of lines set to 1 and all cells have fixed height (60 px in my case). When the button in the cell is tapped, then the UILabel's number of lines is set to 0 and word wrap is turned on, effectively expanding the table cell.
Now, the issue is that only the implementation of UITableViewCell knows whether the label is expanded or not - and thus what the cell height should be. However the owner file is the table's datasource.
I can't get may head around how to set this up. Any ideas are appreciated.
Update here are extracts from my code
In the custom UITableViewCell implementation:
- (float)requiredHeight
{
if(isFull)
{
CGSize labelSize = [LblTitle.text sizeWithFont: [LblContent font]
constrainedToSize: CGSizeMake(300.0f, 300.0f)
lineBreakMode: UILineBreakModeTailTruncation];
return 42.0f + labelSize.height;
}
else
{
return 60.0f;
}
}
In owner file (UITableViewDelegate):
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
OOCommentCell *cell = (OOCommentCell*)[tableView cellForRowAtIndexPath:indexPath];
return [cell requiredHeight];
}
However this results randomly in an infinite loop or in BAD_ACCESS_EXCEPTION.