gpt4 book ai didi

ios - UIAlertController 和 UIViewAlertForUnsatisfiableConstraints 错误

转载 作者:行者123 更新时间:2023-12-01 10:00:59 26 4
gpt4 key购买 nike

我昨天升级到 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 (以红色突出显示)

enter image description here

这是我的代码:


@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
}

}

我试过设置我的 UIAlertController 的宽度。通过在我的 promptPhoto() 中使用此代码方法无效。

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宽度,以便我可以摆脱我的错误信息?

先感谢您。

最佳答案

这可能是一个 Xcode 错误。仍然苹果没有修复它。这个错误也发生在最新的 xcode 11.3.1

关于ios - UIAlertController 和 UIViewAlertForUnsatisfiableConstraints 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55391842/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com