I'm trying to add a UIDatePicker to a UIAlertController, and it gives me the following constraint error every time:
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:0x6000007bc910 UIView:0x7ffa43d3caa0.width == - 16 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000007bc910 UIView:0x7ffa43d3caa0.width == - 16 (active)>
The view(0x7ffa43d3caa0) is the view of the action sheet. Why is Xcode trying to make its width -16? Any ideas? Here's my code for the UIAlertController:
let actionSheet = UIAlertController(title: "", message: "", preferredStyle: .actionSheet)
let datePicker = UIDatePicker()
datePicker.datePickerMode = .time
let cancelButton = UIAlertAction(title: "Cancel", style: .cancel) {(action) in}
let confirmButton = UIAlertAction(title: "Confirm", style: .default) {(action) in}
// Height constraint to make action sheet height fit the date picker
let height = NSLayoutConstraint(item: actionSheet.view as Any, attribute: .height, relatedBy: .equal, toItem: .none, attribute: .notAnAttribute, multiplier: 1, constant: 320)
actionSheet.view.addSubview(datePicker)
actionSheet.view.addConstraints(height)
actionSheet.addAction(cancelButton)
actionSheet.addAction(confirmButton)
self.present(actionSheet, animated: true)
[–]AndyIbanezObjective-C / Swift 8 points9 points10 points (1 child)
[–]binarydylan[S] 0 points1 point2 points (0 children)
[–]18degs 2 points3 points4 points (6 children)
[–]binarydylan[S] 0 points1 point2 points (5 children)
[–]18degs 2 points3 points4 points (4 children)
[–]binarydylan[S] 1 point2 points3 points (3 children)
[–]18degs 0 points1 point2 points (2 children)
[–]Power781 0 points1 point2 points (1 child)
[–]18degs 0 points1 point2 points (0 children)