gpt4 book ai didi

ios - 如何修复 Swift 中的 "ActionSheet of UIAlertController has the conflict constraint"错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:59:23 26 4
gpt4 key购买 nike

我的代码在iOS12.1上运行成功,但是最近当我将iOS、Xcode、macOS的版本更新到iOS12.2 Xcode10.2和macOS10.14.4时,我的项目出现了问题。我的应用程序界面没有问题,但是当我打开操作表时,它告诉我我的约束有冲突。我该如何解决? this is my UI this is the warning in Xcode

我重新设置了接口(interface)的约束,但是不管怎么弄,还是一样的问题。

这些是我的代码,一旦我点击按钮,就会出现操作表,Xcode 告诉我我的约束有冲突

@IBAction func newToDoBarButtonTapped(_ sender: UIBarButtonItem) {

let alertController = UIAlertController(title: "New or Edit", message: nil, preferredStyle: .actionSheet)
let newToDoAlertAction = UIAlertAction(title: "New Item", style: .default, handler: {(_) in
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let registerVC = mainStoryboard.instantiateViewController(withIdentifier: "NewToDoStoryboard") as! ToDoViewController
self.navigationController?.pushViewController(registerVC, animated: true)
})

let editInformationOfListAction = UIAlertAction(title: "Edit Information", style: .default, handler: {(_) in
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let registerVC = mainStoryboard.instantiateViewController(withIdentifier: "EditStoryboard") as! EditItemTableViewController
self.navigationController?.pushViewController(registerVC, animated: true)
})

let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)

alertController.addAction(newToDoAlertAction)
alertController.addAction(editInformationOfListAction)
alertController.addAction(cancelAction)

self.present(alertController,animated: true,completion: nil)
}

我除了没有约束冲突的警告。

最佳答案

您可能必须手动关闭约束警报。

   @IBAction func newToDoBarButtonTapped(_ sender: UIBarButtonItem) {
...
self.present(alertController,animated: true,completion: nil)

alertController.view.subviews.flatMap({$0.constraints}).filter{ (one: NSLayoutConstraint)-> (Bool) in
return (one.constant < 0) && (one.secondItem == nil) && (one.firstAttribute == .width)
}.first?.isActive = false

}

关于ios - 如何修复 Swift 中的 "ActionSheet of UIAlertController has the conflict constraint"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55430168/

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