I am trying to calculate the height of a table view cell that is layout using auto layout. As this has to be compatible to iOS7 as well, I need to return a valid height for heightForRowAtIndexPath:
.
What I am doing is the following:
if (self.userRatingsAbbreviatedTextCell == nil) {
self.userRatingsAbbreviatedTextCell = [[UserRatingsAbbreviatedTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
[self.userRatingsAbbreviatedTextCell prepareForReuse];
UserRating *rating = [self.paginationModel ratingAtIndex:reviewIndex];
[self.userRatingsAbbreviatedTextCell configureCellForHotelUserRating:rating];
[self.userRatingsAbbreviatedTextCell layoutIfNeeded];
CGSize size = [self.userRatingsAbbreviatedTextCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height;
The cell has a disclosure indicator. When I ask the cell for its contentView
width it is 296
. However in cellForRowAtIndexPath:
after dequeuing a cell, its contentView
width is 289
, which is the size that is used for rendering. Has anybody experienced such issues? What do I need to do for the cell to set its contentView
width correctly?