Here is the code snippet
self.xyzIcon = [UIImage mobileImageNamed:@"icon_xyz"];
self.xyzIconImageView = [UIImageView new];
[self.contentView addSubview:self.xyzIconImageView];
[self.xyzIconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(weakSelf.contentView.mas_left);
make.width.equalTo(@(weakSelf.xyzIcon.size.width));
make.height.equalTo(@(weakSelf.xyzIcon.size.height));
}];
In the view controller, which uses tableview
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (!self.prototypeCell) {
self.prototypeCell = [UITableViewCell new];
}
[self.prototypeCell configure];
CGFloat heightCalculated = [self.prototypeCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height + 1.f;
NSLog(@"Height calculated %f", heightCalculated);
returns heightCalculated;
}
This always returns 1.f. Please help and I am not sure what I am doing wrong here.
The problem is that your constraints are not determinative of the height of the cell. You have not pinned the top of the image view or the bottom of the image view to its superview (the contentView
). So the cell has nothing internal to keep it from collapsing all the way to zero, as it were, when you call systemLayoutSizeFittingSize
.
To put it another way: the way systemLayoutSizeFittingSize
works is by treating something's internal constraints as struts that give it a minimum (or maximum) size. You have no struts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With