UIAlertController 和 UIViewAlertForUnsatisfiableConstraints 错误
Posted
技术标签:
【中文标题】UIAlertController 和 UIViewAlertForUnsatisfiableConstraints 错误【英文标题】:UIAlertController and UIViewAlertForUnsatisfiableConstraints error 【发布时间】:2019-08-18 21:13:22 【问题描述】:我昨天升级到 Xcode 10.2 并开始使用 Swift 5,并在弹出我的 UIAlertController
照片提示时注意到此错误。我不记得在 Xcode 10.1 中看到过它
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x600001321e00 UIView:0x7fe1246070a0.width == - 16 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
我读过这个问题How to trap on UIViewAlertForUnsatisfiableConstraints?
并且能够将错误指向我的UIAlertController
(以红色突出显示)
这是我的代码:
@objc private func promptPhoto()
let prompt = UIAlertController(title: "Choose a Photo",
message: "",
preferredStyle: .actionSheet)
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
let camerAction = UIAlertAction(title: "Camera", style: .default) _ in
guard self.isCameraAccessible() else
self.showAlert(title: "Oops", message: "Camera is not available")
return
imagePicker.sourceType = .camera
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true)
let libraryAction = UIAlertAction(title: "Photo Library", style: .default) _ in
imagePicker.sourceType = .photoLibrary
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true)
let cancelAction = UIAlertAction(title: "Cancel",
style: .cancel,
handler: nil)
prompt.addAction(camerAction)
prompt.addAction(libraryAction)
prompt.addAction(cancelAction)
present(prompt, animated: true)
// Prevent closing the prompt by touch up outside the prompt.
prompt.view.superview?.subviews[0].isUserInteractionEnabled = false
我尝试在promptPhoto()
方法中使用此代码设置UIAlertController
的宽度,但无济于事。
let width: NSLayoutConstraint = NSLayoutConstraint(item: prompt.view!,
attribute: NSLayoutConstraint.Attribute.width,
relatedBy: NSLayoutConstraint.Relation.equal,
toItem: nil,
attribute: NSLayoutConstraint.Attribute.notAnAttribute,
multiplier: 1,
constant: self.view.frame.width)
prompt.view.addConstraint(width)
有没有办法控制UIAlertController
的宽度以便我可以摆脱我的错误消息?
提前谢谢你。
【问题讨论】:
在你的Build Setting -> Swift Compiler - Language
中使用Swift 5
或Swift 4.2
?
@Nizzam Swift 语言版本设置为 Swift 5
我想说别担心,这似乎是 UIAlertController 中的内部布局不一致。
这似乎是一个错误:openradar.appspot.com/49289931
这个问题还没有解决吗?一直打印错误
【参考方案1】:
这可能是一个 Xcode 错误。仍然苹果没有修复它。这个错误也发生在最新的 xcode 11.3.1
【讨论】:
以上是关于UIAlertController 和 UIViewAlertForUnsatisfiableConstraints 错误的主要内容,如果未能解决你的问题,请参考以下文章
UIAlertController 和 UIViewAlertForUnsatisfiableConstraints 错误