故事板中的自定义uitableViewCell在iOS8.1中失去了自动布局约束

时间:2014-12-12 06:43:32

标签: ios autolayout tableviewcell

问题是我可以获得自定义UITableViewCell(自定义backgroundColor已更改), 但其中的限制都已丢失。

PS。我正在使用Xcode 6.1.1。

我希望获得正确的高度值,但所有约束都会丢失。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

        static HomeMainNewsCell *mainCell = nil;

        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            mainCell = [self.tableView dequeueReusableCellWithIdentifier:@"HomeMainNewsCell"];
        });
        [mainCell.titleLabel setText:@"dsfjsdhfjsasdfsdfdsfsdfsdfsdfk"];
        [mainCell layoutIfNeeded];

        CGFloat height = [mainCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
        return height;
}

是日志

 po [mainCell.contentView constraints]
<__NSArrayM 0x7fe05b745c10>(

)

这是故事板截图

enter image description here

添加信息

删除heightForRowAtIndexPath methed后,它在iOS8.1中显示完美。

但在iOS7.1中,它显示为每个单元格的高度值为44.并且约束都回来了。

po [mainCell.contentView constraints]
<__NSArrayM 0x78e50f20>(
<NSLayoutConstraint:0x78e52a10 UILabel:0x78e524d0.trailing == UITableViewCellContentView:0x78e52230.trailing - 8>,
<NSLayoutConstraint:0x78e52a40 V:[UILabel:0x78e524d0]-(17)-|   (Names: '|':UITableViewCellContentView:0x78e52230 )>,
<NSLayoutConstraint:0x78e52a70 H:|-(8)-[UILabel:0x78e524d0]   (Names: '|':UITableViewCellContentView:0x78e52230 )>,
<NSLayoutConstraint:0x78e52aa0 V:[UILabel:0x78e52380]-(9)-[UILabel:0x78e524d0]>,
<NSLayoutConstraint:0x78e52ad0 UILabel:0x78e52380.trailing == UITableViewCellContentView:0x78e52230.trailing - 8>,
<NSLayoutConstraint:0x78e52b00 V:[UIImageView:0x78e522d0]-(9)-[UILabel:0x78e52380]>,
<NSLayoutConstraint:0x78e52b30 H:|-(8)-[UILabel:0x78e52380]   (Names: '|':UITableViewCellContentView:0x78e52230 )>,
<NSLayoutConstraint:0x78e52b60 H:|-(0)-[UIImageView:0x78e522d0]   (Names: '|':UITableViewCellContentView:0x78e52230 )>,
<NSLayoutConstraint:0x78e52b90 H:[UIImageView:0x78e522d0]-(0)-|   (Names: '|':UITableViewCellContentView:0x78e52230 )>,
<NSLayoutConstraint:0x78e52bc0 V:|-(0)-[UIImageView:0x78e522d0]   (Names: '|':UITableViewCellContentView:0x78e52230 )>
)

1 个答案:

答案 0 :(得分:1)

最后,我找到了一个完美的解决方案。

这个问题的原因是在iOS8中使用tableView.rowHeight = UITableViewAutomaticDimension进行自动布局,它比以前更好,更好。

解决方案的帖子来自这里。

http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=18517

解决方案太酷了~~感谢大家对这个问题的评论。