【问题标题】:UIAlertController's actionSheet gives constraint error on iOS 12.2 / 12.3 [duplicate]UIAlertController 的 actionSheet 在 iOS 12.2 / 12.3 上给出约束错误 [重复]
【发布时间】:2019-08-17 17:14:42
【问题描述】:

在 iOS 12.2 上,使用 UIAlertControlleractionSheet 时,Xcode 会出现约束错误。有人遇到这个问题吗?

同样的代码在 iOS 12.1 上运行没有错误。

我已经在 Xcode 10.2 和 10.1 上测试过这段代码。

class ViewController: UIViewController {
    
    let Click : UIButton = {
        let button = UIButton(type: UIButton.ButtonType.system)
        button.translatesAutoresizingMaskIntoConstraints = false
        button.setTitle("OK", for: .normal)
        button.tintColor = UIColor.blue
        button.addTarget(self, action: #selector(click(_:)), for: UIControl.Event.touchUpInside)
        return button
    }()

    override func viewDidLoad() {
        super.viewDidLoad()
        view.addSubview(Click)
        Click.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        Click.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
    }

    
    @objc func click(_ sender: UIButton) {
        let optionMenu = UIAlertController(title: nil, message: "Choose Option", preferredStyle: .actionSheet)
        
        let deleteAction = UIAlertAction(title: "Delete", style: .default)
        let saveAction = UIAlertAction(title: "Save", style: .default)
    
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
        
        optionMenu.addAction(deleteAction)
        optionMenu.addAction(saveAction)
        optionMenu.addAction(cancelAction)
        
        self.present(optionMenu, animated: true, completion: nil)
    }

}
[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:0x6000001b6ee0 UIView:0x7fe3b6513020.width == - 16   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x6000001b6ee0 UIView:0x7fe3b6513020.width == - 16   (active)>

PS:

为了确保问题出在UIAlertController,我删除了所有内容并更新了如下代码,但我收到了同样的错误:

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        let optionMenu = UIAlertController(title: "Test", message: "Choose Option", preferredStyle: .actionSheet)
        
        let deleteAction = UIAlertAction(title: "Delete", style: .default)
        let saveAction = UIAlertAction(title: "Save", style: .default)
        
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel)
        
        optionMenu.addAction(deleteAction)
        optionMenu.addAction(saveAction)
        optionMenu.addAction(cancelAction)
        
        self.present(optionMenu, animated: true, completion: nil)
    }
    
}

【问题讨论】:

  • 我已经测试了你的代码,它运行完美。你能提供一个实际的屏幕截图吗
  • 假设是 12.2 更新问题
  • 我在运行 iOS 12.2 的 Xcode 10.2 中遇到了同样的问题——我猜这是一个错误!我打算忽略它。
  • 与 12.2 相同的问题。 12.1没有这个问题。
  • 即使是 12.3,XCode 10.2.1

标签: swift5 uialertcontroller ios12


【解决方案1】:

这是 iOS 版本中的一个错误:

  • 12.2
  • 12.3
  • 12.4
  • 13.0
  • 13.1
  • 13.2
  • 13.2.3
  • 13.3
  • 13.4
  • 13.4.1
  • 13.5
  • 13.5.1
  • 13.6
  • 14.0
  • 14.1
  • 14.2
  • 14.4

我们唯一能做的就是向 Apple 提交错误报告(我刚刚这样做了,你也应该这样做)。

如果错误仍然存​​在,我将尝试为新版本的 iOS 更新答案。帮助表示赞赏。

【讨论】:

  • 该错误在 iOS 13 beta 2 中继续存在。
  • iOS 13正式版继续
  • iOS 13.2 登录,问题依旧
  • 它也存在于 ios 13.3 中
  • 2020 年 6 月 22 日,仍然看到此错误。这太荒谬了。
猜你喜欢
  • 1970-01-01
  • 2019-03-15
  • 1970-01-01
  • 1970-01-01
  • 2014-11-10
  • 1970-01-01
  • 1970-01-01
  • 2019-06-10
  • 2016-02-01
相关资源
最近更新 更多