我想展示一个来自ContainerVC的PopOverPresentationVC(从Storyboard加载)。我的代码如下:-
@IBAction func showPopOverVC(view: UIView){
let embeddedVC: EmbeddedVC = instantantiateVC() // my personal helper method
embeddedVC.popoverPresentationController?.sourceView = view
embeddeVC.modalPresentationStyle = .popover
present(embeddedVC, animated: true)
}
尽管我正确设置了sourceView,但我不断收到此错误
UIPopoverPresentationController should have a non-nil sourceView or barButtonItem set before the presentation occurs.
。任何建议,不胜感激。如果我删除该行,这很有趣:-
embeddeVC.modalPresentationStyle = .popover
模态演示效果很好。
最佳答案
因此,答案是您需要按此顺序设置popover演示文稿属性,如果您反向操作,则应用程序将崩溃,疯狂的我说:)
embeddeVC.modalPresentationStyle = .popover
embeddedVC.popoverPresentationController?.sourceView = view