我有一个 iPhone 应用程序,我正在尝试将其制作为通用应用。我有以下代码:
let documentMenu = UIDocumentMenuViewController(documentTypes: [kUTTypeContent as String], inMode: .Import)
documentMenu.modalPresentationStyle = .FormSheet
documentMenu.delegate = self
self.presentationContext.presentViewController(documentMenu, animated: true, completion: nil)
self.presentationContext
是传递给类的视图控制器。
每次执行此代码时,都会出现以下错误:
您的应用程序已显示了一个 UIDocumentMenuViewController ()。在其当前的特征环境中,具有此样式的 UIDocumentMenuViewController 的 modalPresentationStyle 为 UIModalPresentationPopover。您必须通过视图控制器的 popoverPresentationController 提供此弹出窗口的位置信息。您必须提供 sourceView 和 sourceRect 或 barButtonItem 中的任一项。如果在呈现视图控制器时不知道此信息,可以在 UIPopoverPresentationControllerDelegate 方法 -prepareForPopoverPresentation 中提供它。
我不确定发生了什么。我甚至尝试设置 sourceView
和 sourceRect
,这确实停止了错误,但是它将 DocumentMenuViewController
粘贴到了弹出窗口中,我不需要那样做。我需要以模态方式在屏幕中央呈现此视图控制器。谢谢您的帮助。
UIDocumentMenuViewController
的实际经验,而你在问题中提到的经验与我所见相符。 - rmaddy