我正在尝试创建一个包含 4 个 UILabels
和一个 UITextView
的自定义单元格。我已经列出了要素。 UITextView
不可滚动。我遇到的问题是将最后一个 UILabel
放在 UITextView
下。我试过将两者(其中之一)固定到 super View ,但似乎没有任何效果。它总是在 UITextView
下面,如下所示:
要将 UILabel 移动到 UITextView 下方,我还应该做些什么?
这是我对代码所做的唯一更改:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
QXTInboxCell *inboxCell = (QXTInboxCell*)[self tableView:tableView cellForRowAtIndexPath:indexPath];
CGFloat width = self.tableView.frame.size.width - inboxCell.question.frame.origin.x - QUESTION_RIGHT_MARGIN;
CGSize size = [inboxCell.question sizeThatFits:CGSizeMake(width, 400)];
[inboxCell.question sizeThatFits:size];
return (inboxCell.question.frame.origin.y + size.height + 20);
}
请帮忙。我在 XCode 5.0.2 上。谢谢。
最佳答案
添加以下约束:
- TextView 到 superview(顶部空间)
- TextView 到标签(底部/顶部空间)
- 标签到 super View (底部空间)
然后(在设置 textView 的文本之后)调用
[cell setNeedsLayout]
当然,这只有在您为 heightForRowAtIndexPath:
中的单元格计算出正确的高度时才有效。
关于ios - UITableViewCell 和自动布局的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20491120/