[英]how to add a constrains to fix tableview to its parent bottom
i have a container in my view with two tableview controllers as childs. 我在我的视图中有一个容器,其中有两个tableview控制器作为子容器。
i have the childs as this properties in class
我在班级有孩子
lazy var photoFeedVC: UserPicsTableViewController = self.makeAndAddVC()
lazy var postFeedVC: PostFeedVC = self.makeAndAddVC()
the function to make the childs 使孩子成长的功能
func makeAndAddVC<T: UIViewController>() -> T {
let vc = T()
self.addChildViewController(vc)
return vc
}
i want to fix each tableview to its container bottom after i increase the size of the container in viewDidAppear. 我想在viewDidAppear中增加容器的大小后,将每个tableview固定到其容器底部。
photoFeedVC.tableView.snp.makeConstraints({(make) -> Void in
make.bottom.equalTo(containerView)
})
postFeedVC.tableView.snp.makeConstraints({ make -> Void in
make.bottom.equalTo(self.view)
})
this is a contrainst tryin to fix to bottom but xcode gave me this error 这是一个固定的尝试,但xcode给了我这个错误
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors and because they have no common ancestor.
***由于未捕获的异常“ NSGenericException”而终止应用程序,原因:“无法激活具有锚点的约束,并且它们没有共同的祖先。 Does the constraint or its anchors reference items in different view hierarchies?
约束或其锚点是否引用了不同视图层次结构中的项目? That's illegal.'
那是非法的。
here the method to increase the container 这里增加容器的方法
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
print("aparecio la vista")
containerView.frame.size.height += 150
self.feed.frame.size.height += 150.0
self.photoFeedVC.tableView.frame.size.height += 150.0
self.postFeedVC.tableView.frame.size.height += 150
self.scrollView.contentSize.height = containerView.height + 10
self.scrollView.layoutIfNeeded()
}
The error message in question is saying you're pinning 2 views that aren't in the same hierarchy. 有问题的错误消息是您要固定两个不在同一层次结构中的视图。 You're missing an
addSubview()
call somewhere (though I can't say exactly where, because there seem to be a lot of child view controllers and I'm not sure what the hierarchy should look like). 您在某处缺少了一个
addSubview()
调用(尽管我不能确切说出位置,因为似乎有很多子视图控制器,而且我不确定层次结构应该是什么样子)。
You're also doing both frame math and auto layout, which, except in very rare cases, is not what you want. 您还同时在进行框架数学和自动布局,这在极少数情况下不是您想要的。 If you want to be using auto layout, you should be modifying constraints to expand a container, not adjusting anything's
frame.height
. 如果要使用自动布局,则应修改约束以扩展容器,而不要调整任何东西的
frame.height
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.