【发布时间】:2016-12-02 11:56:00
【问题描述】:
当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.'
【问题讨论】:
-
崩溃报告是什么
-
请edit您的问题,而不是评论如此复杂的内容。谢谢。
-
@EricAya 对不起。已编辑的问题。
-
@D.Finna 没问题。感谢您的编辑。 :)
标签: ios swift uitableview uiview