我想显示一个UIView,其中有一个标签,说:“你没有帖子”,当update.count == 0
。我试图做到这一点,但当我尝试时,应用程序崩溃。以编程方式显示UIView,当没有帖子得到
我做错了什么?这里是我的代码:
let noPostView: UIView = {
let iv = UIView()
iv.backgroundColor = UIColor.whiteColor()
//iv.image = UIImage(named: "iphoneSample")
//iv.clipsToBounds = true
return iv
}()
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if updates.count == 0 {
noPostView.anchorToTop(tableView.topAnchor, left: tableView.leftAnchor, bottom: tableView.bottomAnchor, right: tableView.rightAnchor)
noPostView.heightAnchor.constraintEqualToConstant(100).active = true
noPostView.widthAnchor.constraintEqualToConstant(100).active = true
tableView.addSubview(noPostView)
}
return updates.count
}
得到这个错误当中更多:
*** Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x61000067f280 "UIView:0x7fdbcbd21490.top"> and <NSLayoutYAxisAnchor:0x610000660a40 "UITableView:0x7fdbcd86a600.top"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'
什么崩溃报告 –
请编辑您的问题,而不是评论这样复杂的内容。谢谢。 – Moritz
@EricAya对不起。编辑的问题。 –