我在自定义 UITableViewCellself.username, self.postText, self.containerView
中有三个视图:另外两个的超级视图在哪里self.containerView
。我希望它像这样布置:
Contrainer = self.containerView
-----------------------------
|.....5pt-margin............|
| [self.username] |
| [self.postText]* |
|.....5pt-margin............|
----------------------------
* Posttext can have a dynamic height - and the superview's height should adapt dynamically based on this height
我在单元格的 init 方法中尝试了以下 NSLayoutConstraint:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[...]
NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(self.username, self.postText, self.containerView);
[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(5)-[self.username]-[self.postText]-(5)-|" options:0 metrics:nil views:viewsDictionary];
}
return self;
}
它目前在没有任何日志的情况下崩溃。正确的 NSLayoutConstraint 应该如何看?