我UITableView
在 Storyboard 中创建了一个,添加了所需的自动布局约束。我想在单击表格单元格时显示一个操作表,因此我编写了以下代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: false)
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Play Video", style: .default, handler: { (action) -> Void in
// Play Video
}))
actionSheet.addAction(UIAlertAction(title: "Share", style: .default, handler: { (action) -> Void in
// Share
}))
actionSheet.addAction(UIAlertAction(title: "Delete", style: .destructive, handler: { (action) -> Void in
// Delete
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(actionSheet, animated: true, completion: nil)
}
Xcode 在构建时不会抱怨任何自动布局问题(没有警告/错误)。但是,当我运行应用程序并单击触发上述功能的表格单元格时,Xcode 控制台显示自动布局错误:
2019-07-18 15:35:03.472831+0800 MP4Convert[2797:357238] [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:0x2808bf8e0 UIView:0x104f16800.width == - 16 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x2808bf8e0 UIView:0x104f16800.width == - 16 (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.
该值- 16
永远不会出现在所有约束中。我尝试将标识符添加到现有约束中,但似乎NSLayoutConstraints
上面提到的不存在。
我错过了什么?
UIViewController
层次结构非常简单:
UIView > UITableView > UITableViewCell
在设备屏幕上显示时没有视觉上的不一致。
iPhone Xr 设备上的 Xcode 10.2.1、iOS 12.3.1