【发布时间】:2020-09-11 12:17:12
【问题描述】:
我正在尝试使用 UIDocumentInteractionController 在 Xamarin Forms for IOS 平台中打开下载的文件,并通过 web 服务访问特定于平台的类,但它给我的问题是“尝试呈现其视图不在窗口层次结构中的 QLPreviewController”
public void viewFile(string path)
{
var PreviewController = UIDocumentInteractionController.FromUrl
(NSUrl.FromFilename(path));
PreviewController.Delegate = new UIDocumentInteractionControllerDelegateClass
(UIApplication.SharedApplication.KeyWindow.RootViewController.PresentedViewController);
Device.BeginInvokeOnMainThread(() =>
{
PreviewController.PresentPreview(true);
});
}
以下是 UIDocumentInteractionControllerDelegateClass 代码:
public class UIDocumentInteractionControllerDelegateClass : UIDocumentInteractionControllerDelegate {
UIViewController ownerVC;
public UIDocumentInteractionControllerDelegateClass(UIViewController vc)
{
ownerVC = vc;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
{
return ownerVC;
}
public override UIView ViewForPreview(UIDocumentInteractionController controller)
{
return ownerVC.View;
}
}
【问题讨论】:
-
请贴出相关代码
标签: c# ios xamarin.forms