Ios 将UITableView约束为其superview';s边导致布局冲突
我有一个简单的Ios 将UITableView约束为其superview';s边导致布局冲突,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个简单的UITableView,我在viewDidLoad中将它约束到它的超级视图的边缘 UITableView *tableView = [[UITableView alloc] init]; [tableView setBackgroundColor:[UIColor blackColor]]; tableView.delegate = self; tableView.dataSource = self; tableView.rowHeight = 44; [tableView reg
UITableView
,我在viewDidLoad
中将它约束到它的超级视图的边缘
UITableView *tableView = [[UITableView alloc] init];
[tableView setBackgroundColor:[UIColor blackColor]];
tableView.delegate = self;
tableView.dataSource = self;
tableView.rowHeight = 44;
[tableView registerClass:Cell.self forCellReuseIdentifier:@"cell"];
[self.view addSubview:tableView];
[NSLayoutConstraint constraintWithItem:tableView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:tableView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:tableView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0].active = YES;
[NSLayoutConstraint constraintWithItem:tableView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0].active = YES;
[self.view layoutIfNeeded];
但是,在构建和运行控制台时,我会遇到两个布局问题:
2017-08-24 12:08:21.676379-0400目标测试[62354:48633213]
[LayoutConstraints]无法同时满足约束。
可能以下列表中至少有一个约束是
你不会想要的。尝试以下方法:(1)查看每个约束并尝试
找出你不期望的;(2) 查找添加了
一个或多个不需要的约束,然后修复它。(注意:如果您是
看到您不了解的NSAutoresizingMaskLayoutConstraints,
请参阅UIView属性的文档
翻译自动调整大小(从皮肤到肌肉)(
"",
UITableView:0x7FCF017600(活动,名称:
“|”:UIView:0x7fcf0c604bf0)>”,
"
(现行)>“,
“”)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建符号断点
要在调试器中捕获此信息。研究方法
中列出的UIView上的UIConstraintBasedLayoutDebugging类别
也可能有帮助
2017-08-24 12:08:21.677146-0400
objtest[62354:48633213][LayoutConstraints]无法同时执行
满足约束条件。可能至少有一个约束在
下面的列表是您不想要的。试试这个:(1)看看每一个
约束并试图找出你不期望的;(2) 发现
添加一个或多个不需要的约束并对其进行修复的代码。
(注意:如果您看到NSAutoresizingMaskLayoutConstraints
不理解,请参阅UIView属性的文档
翻译自动调整大小(从皮肤到肌肉)(
"",
"",
"
(现行)>“,
“”)
将尝试通过打破约束进行恢复
在UIViewAlertForUnsatifiableConstraints处创建符号断点
要在调试器中捕获此信息。研究方法
中列出的UIView上的UIConstraintBasedLayoutDebugging类别
也可能有帮助
任何帮助都会很好!谢谢 看来你忘了:
tableView.translatesAutoresizingMaskIntoConstraints = NO;
看来你忘了:
tableView.translatesAutoresizingMaskIntoConstraints = NO;