使用UITableViewAutomaticDimension时UITableViewCell高度错误

rab*_*ace 7 uitableview ios autolayout

我使用2个多线标签制作自定义单元格,并将此标签固定到所有边.当在-tableView:heightForRowAtIndexPath:用于iOS的> = 8我返回UITableViewAutomaticDimension.但是当表视图出现时,单元格高度应该比应该大.向下滚动然后向上滚动单元格取正常高度.如何解决这个问题?

高度代码:

   - (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;
}
Run Code Online (Sandbox Code Playgroud)

结果如下:

滚动后:

rab*_*ace 10

当我没有为iOS 8设置tableView的estimatedRowHeight并且每次设置多行标签的文本时更新preferredMaxLayoutWidth时问题就消失了