【发布时间】:2017-10-31 15:45:28
【问题描述】:
我正在尝试使用 Autolayout 在我的 UITableView 中创建以下设置,然后将其添加为其包装 UIView 的子视图。
到目前为止,我正在使用以下内容,但一点运气都没有。这是据我所知,它正在引发错误。
//Trailing
NSLayoutConstraint *trailing =[NSLayoutConstraint
constraintWithItem:self.tableViewVideoList
attribute:NSLayoutAttributeTrailing
relatedBy:NSLayoutRelationEqual
toItem:self.viewContentWrapper
attribute:NSLayoutAttributeTrailing
multiplier:1.0f
constant:0.f];
//Leading
NSLayoutConstraint *leading = [NSLayoutConstraint
constraintWithItem:self.tableViewVideoList
attribute:NSLayoutAttributeLeading
relatedBy:NSLayoutRelationEqual
toItem:self.viewContentWrapper
attribute:NSLayoutAttributeLeading
multiplier:1.0f
constant:0.f];
//Bottom
NSLayoutConstraint *bottom =[NSLayoutConstraint
constraintWithItem:self.tableViewVideoList
attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual
toItem:self.viewContentWrapper
attribute:NSLayoutAttributeBottom
multiplier:1.0f
constant:0.f];
[self.viewContentWrapper addConstraint:trailing];
[self.viewContentWrapper addConstraint:bottom];
[self.viewContentWrapper addConstraint:leading];
[self.viewContentWrapper addSubview:self.tableViewVideoList];
任何帮助都会非常感谢,我通常会在 Storybaord 中完成所有自动布局工作。
【问题讨论】:
-
您面临哪些错误?
-
在添加固定约束之前需要将表视图添加为子视图
-
我认为您还需要通过添加顶部约束或显式设置高度来设置 tableview 的高度
标签: ios objective-c autolayout