I create a custom cell with two multi-line labels and bind these labels to all sides. When in -tableView:heightForRowAtIndexPath: for iOS> = 8, I return UITableViewAutomaticDimension . But when a table view appears, the cell height is greater than it should be. After scrolling down and then scrolling up, the cell takes up a normal height. How to fix this behavior?
Code for height:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) { return UITableViewAutomaticDimension; } static CCTopicTableViewCell *cell; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ cell = [tableView dequeueReusableCellWithIdentifier:@"topicCellIdentifier"]; }); cell.topic = [self.topics topicAtIndexPath:indexPath]; cell.bounds = CGRectMake(0, 0, CGRectGetWidth(self.tableView.bounds), CGRectGetHeight(cell.bounds)); [cell setNeedsLayout]; [cell layoutIfNeeded]; CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; return size.height + 1; }
And the result:

After scrolling:

source share