I created a UITableView
in Storyboard, added required Auto Layout constraints. I want to display an action sheet when a table cell is clicked, therefore I write the following codes:
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 doesn't complain about any auto layout issues (no warning/errors) in Build time. However, when I run the App and click the table cell triggering the functions above, Xcode console shows an Auto Layout error:
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.
The value - 16
never appears in the all constraints. I try to add identifiers to existing constraints, but seems the NSLayoutConstraints
mentioned above does not exist.
What did I miss?
The UIViewController
hierarchy is very simple:
UIView > UITableView > UITableViewCell
There is no visual inconsistency when displaying in device's screen.
Xcode 10.2.1, iOS 12.3.1 on iPhone Xr device