UIAlertController's actionSheet gives constraint error on iOS 12.2 / 12.3 [duplicate]

纵然是瞬间 提交于 2019-12-04 07:32:53

问题


On iOS 12.2. while using UIAlertController's actionSheet Xcode, gives constraint error anyone having this problem

This same code runs on iOS 12.1 with no error

I have tested this code on Xcode 10.2 and 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:

Just to make sure that the problem is on UIAlertController I remove everything and update the code as below but same error.

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

}

回答1:


It's a new bug in iOS versions:

  • 12.2
  • 12.3
  • 12.4
  • 13.0
  • 13.1
  • 13.2
  • 13.2.3

The only thing we can do is to file a bug report to Apple (just did that).

I'll try to update answer for a new version(s) of iOS when it come out.



来源:https://stackoverflow.com/questions/55372093/uialertcontrollers-actionsheet-gives-constraint-error-on-ios-12-2-12-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!