我有聊天表的动态单元格。我有留言标签和时间标签。对比如下
消息标签前导> = 100
消息标签尾随= 15
消息标签top = 10
消息标签底部到时间标签top = 5
时间标签到底= 5
时间标签宽度60和高度21
时间标签尾随= 15
我尝试了很多内容拥抱和贪婪的价值观。 消息标签内容拥抱属性是
水平250
垂直1000
抗压缩性
水平250
垂直1000
第一次正确计算身高。 但是当我在发送或接收消息时添加新单元格时,返回并返回相同视图,其高度增加更多1500 。以下是查找行高的代码。
-(CGFloat)heightForCellAtIndexPath:(NSIndexPath*)indexPath
{
MessageCentreService *message = [[self.dic_messages objectForKey:[self.array_dates objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
static dispatch_once_t onceToken;
static AttendieChatTableViewCell *sizingRightCell = nil;
static AttendieChatTableViewCell *sizingLeftCell = nil;
dispatch_once(&onceToken, ^{
sizingLeftCell = [self.tableView_attendeeChatList dequeueReusableCellWithIdentifier:kCellChatLeftIdentifier];
sizingRightCell = [self.tableView_attendeeChatList dequeueReusableCellWithIdentifier:kCellChatRightIdentifier];
});
sizingLeftCell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight(sizingLeftCell.bounds));
sizingRightCell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(self.tableView_attendeeChatList.frame), CGRectGetHeight(sizingRightCell.bounds));
if(message.message_type == 1)
{
sizingLeftCell.label_message.text = message.message_text;
sizingLeftCell.label_messageTime.text = @"10.30 pm";
[sizingLeftCell setNeedsLayout];
[sizingLeftCell layoutIfNeeded];
CGSize size = [sizingLeftCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height;
}
else
{
sizingRightCell.label_message.text = message.message_text;
sizingRightCell.label_messageTime.text = @"10.30 pm";
[sizingRightCell setNeedsLayout];
[sizingRightCell layoutIfNeeded];
CGSize size = [sizingRightCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return size.height;
}
}
答案 0 :(得分:0)
我也遇到了systemLayoutSizeFittingSize的问题,我通过设置preferredMaxLayoutWidth来修复它。