ios - 无法同时满足从 ios 13 中的 nib 加载的 tableview 单元格的约束
问题描述
我有一个从 nib 文件加载的 tableview 和自定义单元格,这个单元格有一个高度约束(在我的例子中是 80.0),当我启动应用程序时,Xcode 说有一个约束错误。我发现只有当 tableview 有分隔符时才会出现这个问题。如果我想同时拥有单元格的高度约束和表格视图中的分隔符,有没有办法解决这个约束错误?
带表视图的 ViewController
class ViewController: UIViewController, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "SampleTableViewCell", bundle: nil), forCellReuseIdentifier: "SampleTableViewCell")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SampleTableViewCell", for: indexPath) as! SampleTableViewCell
return cell
}
}
我得到的错误
2019-10-13 18:08:04.345180+0300 tableViewProblem[5281:391449] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x600000ca8320 UIView:0x7f988cf0e840.height == 80 (active)>",
"<NSLayoutConstraint:0x600000cb1400 V:[UIView:0x7f988cf0e840]-(0)-| (active, names: '|':UITableViewCellContentView:0x7f988cf0e420 )>",
"<NSLayoutConstraint:0x600000cb14a0 V:|-(0)-[UIView:0x7f988cf0e840] (active, names: '|':UITableViewCellContentView:0x7f988cf0e420 )>",
"<NSLayoutConstraint:0x600000cbcdc0 'UIView-Encapsulated-Layout-Height' UITableViewCellContentView:0x7f988cf0e420.height == 80.5 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600000ca8320 UIView:0x7f988cf0e840.height == 80 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
解决方案
推荐阅读
- linux - 如何根据这两行的单词总和组合两个相邻的行(递归)
- amazon-web-services - 从 Lambda 跨账户调用 CloudFormation API
- jquery - jQuery:从元素中提取值并将其插入可重复列表表单字段的字段中
- tensorflow - 如何确保训练阶段不会面临OOM?
- java - 如何在Java中通过增加循环来获取数量增加的变量(以获取所述变量的值)?
- asp.net-mvc - 自定义身份用户
- sql-server - 每周获取最新的数量更新
- flutter - Flutter中如何在NetworkImage()中添加网络图片列表
- javascript - 使用 Vue js 的单页应用程序的 Web 堆栈
- algorithm - 什么是容器,与其他数据结构有什么区别?