原因:为了保证视图的唯一性,出现了下面的这代码[self.vScrollerView addSubview:cell];
- (void)showConmment:(NSArray *)commentsArray{
if (!commentsArray ||commentsArray.count == 0) return;
#pragma mark 查看更多的控制需要知道当前多少条总的
float cellHeight = PCH_BitMap_BY_SIZE(380);
KapCommentTableViewCell *first;
for (int i = 0; i<commentsArray.count; i++) {
KapCommentTableViewCell *cell = [self createdCellByModel:commentsArray[i]];
[self.vScrollerView addSubview:cell];
if (!first) {
[cell mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.noneCommentPromptLabel);
make.left.right.equalTo(self.titleLabel);
make.height.mas_equalTo(cellHeight);
}];
}else{
[cell mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(first.mas_bottom);
make.left.right.equalTo(self.titleLabel);
make.height.mas_equalTo(cellHeight);
}];
}
first = cell;
}
[self layoutIfNeeded];
}
- (KapCommentTableViewCell *)createdCellByModel:(id)model{
KapCommentTableViewCell *cell = [[KapCommentTableViewCell alloc] init];
cell.userInteractionEnabled = NO;
cell.headerImageView.image= [UIImage imageNamed:[NSString stringWithFormat:@"header_place_%@",model]];
return cell;
}
然后调试的时候,虚拟机没问题,真机报44冲突。。。
<NSLayoutConstraint UITableViewCellContentView.height == 44>)
解决方案:(比较low。。猜测原因是init的时候cell给contentview添加了约束导致的。。。)
- (KapCommentTableViewCell *)createdCellByModel:(id)model{
KapCommentTableViewCell *cell = [[KapCommentTableViewCell alloc] init];
[cell.contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(cell);
}];
cell.userInteractionEnabled = NO;
cell.headerImageView.image= [UIImage imageNamed:[NSString stringWithFormat:@"header_place_%@",model]];
return cell;
}
后续:仍然有约束冲突,但是不影响显示..(看起来像是源码给添加了一个高度为95的约束。。。。导致冲突);
(
"<MASLayoutConstraint:0x1700bf7a0 KapCommentTableViewCell:0x10183ac00.height == 190>",
"<NSLayoutConstraint:0x1702823a0 KapCommentTableViewCell:0x10183ac00.height == 95>"
)
暂未找到解决方法。。。(下面代码并不能解决。。。。)
[cell mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(first.mas_bottom);
make.left.right.equalTo(self.titleLabel);
make.height.mas_equalTo(cellHeight);
}];