【发布时间】:2020-06-08 11:46:35
【问题描述】:
我有一个自定义 UIAlert,我将内容视图控制器设置为我自己的自定义 VC。警报正常运行,但我不断收到此错误:“约束工厂方法传递了一个 nil 布局锚”。我怀疑这与我添加子视图的方式有关,但我试图限制它们无济于事。这是代码:
let vc = UIViewController()
vc.preferredContentSize = CGSize(width: 250,height: 150)
let sortByPicker = UIPickerView(frame: CGRect(x: 0, y: 0, width: 250, height: 150))
sortByPicker.tag = 1
sortByPicker.delegate = self
sortByPicker.dataSource = self
vc.view.addSubview(sortByPicker)
let editRadiusAlert = UIAlertController(title: "Sort Projects By...", message: "", preferredStyle: UIAlertController.Style.alert)
editRadiusAlert.setValue(vc, forKey: "contentViewController")
editRadiusAlert.addAction(UIAlertAction(title: "Done", style: .default, handler: nil))
editRadiusAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(editRadiusAlert, animated: true)
【问题讨论】:
标签: ios swift autolayout nslayoutconstraint uialertcontroller