gpt4 book ai didi

ios - 在 iPad 上呈现 View Controller 只允许 .Popover

转载 作者:行者123 更新时间:2023-12-01 15:55:57 24 4
gpt4 key购买 nike

我有一个 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 只是传递给类的 View Controller 。

每次执行这段代码,都会出现这个错误:

Your application has presented a UIDocumentMenuViewController (). In its current trait environment, the modalPresentationStyle of a UIDocumentMenuViewController with this style is UIModalPresentationPopover. You must provide location information for this popover through the view controller's popoverPresentationController. You must provide either a sourceView and sourceRect or a barButtonItem. If this information is not known when you present the view controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.

我不确定发生了什么。我什至尝试设置 sourceViewsourceRect,这确实会阻止错误,但是,它将 DocumentMenuViewController 粘贴到弹出窗口中,我不要什么那个。我需要将其模态显示在屏幕中央。感谢您的帮助。

最佳答案

以下代码运行良好

let importMenu = UIDocumentMenuViewController(documentTypes: [String(kUTTypePDF)], in: .import)

importMenu.popoverPresentationController?.sourceView = self.view // so that iPads won't crash

importMenu.delegate = self
importMenu.modalPresentationStyle = .formSheet
self.present(importMenu, animated: true, completion: nil)

关于ios - 在 iPad 上呈现 View Controller 只允许 .Popover,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40600168/

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