I have a UILabel inside a UITableViewCell. I am not using autolayout, but creating and adding the views manually. The UILabel can contain a variable amount of text so in my tableview delegate i implement heightForRowAtIndexPath.
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
TableCellWithDocument *cell = (TableCellWithDocument*)[self tableView: tableView cellForRowAtIndexPath: indexPath];
NSLog(@"Cell frame: %@", NSStringFromCGRect(cell.frame));
return [cell heightForCellForWidth: cell.frame.size.width];
The problem i'm having is that when this delegate method is called, the frame size of the cell is not correct. It just returns "default" 320x44. So when i try to calculate the label size, i have the wrong cell width and my cell height gets the wrong height.
In my subclassed TableCellWithDocument class, i can override layoutSubviews and get the correct cell width, but that is too late since heightForRowAtIndexPath has already been called.
How should i handle this?