问题是我可以获得我的自定义 UITableViewCell
(自定义 backgroundColor 已更改),
但其中的约束全部丢失。
附言。我正在使用 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>(
)
这是 Storyboard截图
附加信息
删除heightForRowAtIndexPath方法后,在iOS8.1中显示完美。
但在iOS7.1中,它显示为每个单元格的hight值为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 )>
)
最佳答案
最后,我找到了一个完美的解决方案。
这个问题的原因是在 iOS8 中使用带有自动布局的 tableView.rowHeight = UITableViewAutomaticDimension
并且它比以前工作得更好。
解决方案帖子来自这里。
http://www.raywenderlich.com/forums/viewtopic.php?f=2&t=18517
解决方案太酷了~~感谢大家对这个问题的评论。
关于ios - Storyboard中的自定义 tableViewCell 在 iOS8.1 中失去了它的自动布局约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27438253/