I am trying to create cells with dynamic height, with a single label I have no problem, however when placing two or more labels inside my cell it cuts part of the labels or in certain cases it does not show it.
The height is like this:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
// Calculo
if(!self.myCell) {
self.myCell = [self.tabla dequeueReusableCellWithIdentifier:@"DynamicTableViewCell"];
}
// Config
self.myCell.label.text = [_dataSource[indexPath.row] uppercaseString];
self.myCell.label2.text = [_dataSource[indexPath.row] uppercaseString];
// Layout
[self.myCell layoutIfNeeded];
[self.myCell setNeedsLayout];
// Altura
CGFloat height = [self.myCell.contentView systemLayoutSizeFittingSize:UILayoutFittingExpandedSize].height;
return height;
}
Additionally, my labels have constraints on the Superview and a space between them. In addition, its number of lines is 0 and its break mode (Line Break) is Word Wrap
You are making yourself too complicated. If you have correctly set the constraints and is able to draw the cell, you just have to return UITableViewAutomaticDimension and implement one more method