点击“快速查看”图标后,文档未打开
After tapping on the Quick Look icon the document is not opened
我的任务是实现快速查看功能,以显示打开所选文档的选项。我正在使用 UIDocumentInteractionController 的 PresentOptionsMenu 方法来显示选项。显示了“快速查看”图标,但是当我单击它时没有任何反应。带有选项的弹出窗口关闭,文档未打开。
我做错了什么?为什么点击“快速查看”图标后文档打不开?
The popup displayed after selecting a document
我的代码是:
public class DataViewer
{
public event EventHandler DocumentOpened;
public async Task OpenDocument(string filePath)
{
var viewer = UIDocumentInteractionController.FromUrl(new NSUrl(filePath, false));
viewer.WillBeginSendingToApplication += async (sender, args) =>
{
DocumentOpened?.Invoke(this, EventArgs.Empty);
};
var controller = UIApplication.SharedApplication.KeyWindow.RootViewController;
viewer.PresentOptionsMenu(controller.View.Frame, controller.View, true);
}
}
需要注明ViewController
呈现文档预览。
尝试在委托 UIDocumentInteractionControllerDelegate
中实现方法 ViewControllerForPreview
。
var viewer = UIDocumentInteractionController.FromUrl(new NSUrl(filePath, false));
viewer.WillBeginSendingToApplication += async (sender, args) =>
{
DocumentOpened?.Invoke(this, EventArgs.Empty);
};
var controller = UIApplication.SharedApplication.KeyWindow.RootViewController;
viewer.Delegate = new MyClass(controller); //add this line
viewer.PresentOptionsMenu(controller.View.Frame, controller.View, true);
public class MyClass : UIDocumentInteractionControllerDelegate
{
readonly UIViewController _controller;
public MyClass(UIViewController controller)
{
_controller = controller;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
{
return _controller;
}
public override UIView ViewForPreview(UIDocumentInteractionController controller)
{
return _controller.View;
}
}
参考
我的任务是实现快速查看功能,以显示打开所选文档的选项。我正在使用 UIDocumentInteractionController 的 PresentOptionsMenu 方法来显示选项。显示了“快速查看”图标,但是当我单击它时没有任何反应。带有选项的弹出窗口关闭,文档未打开。
我做错了什么?为什么点击“快速查看”图标后文档打不开?
The popup displayed after selecting a document
我的代码是:
public class DataViewer
{
public event EventHandler DocumentOpened;
public async Task OpenDocument(string filePath)
{
var viewer = UIDocumentInteractionController.FromUrl(new NSUrl(filePath, false));
viewer.WillBeginSendingToApplication += async (sender, args) =>
{
DocumentOpened?.Invoke(this, EventArgs.Empty);
};
var controller = UIApplication.SharedApplication.KeyWindow.RootViewController;
viewer.PresentOptionsMenu(controller.View.Frame, controller.View, true);
}
}
需要注明ViewController
呈现文档预览。
尝试在委托 UIDocumentInteractionControllerDelegate
中实现方法 ViewControllerForPreview
。
var viewer = UIDocumentInteractionController.FromUrl(new NSUrl(filePath, false));
viewer.WillBeginSendingToApplication += async (sender, args) =>
{
DocumentOpened?.Invoke(this, EventArgs.Empty);
};
var controller = UIApplication.SharedApplication.KeyWindow.RootViewController;
viewer.Delegate = new MyClass(controller); //add this line
viewer.PresentOptionsMenu(controller.View.Frame, controller.View, true);
public class MyClass : UIDocumentInteractionControllerDelegate
{
readonly UIViewController _controller;
public MyClass(UIViewController controller)
{
_controller = controller;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
{
return _controller;
}
public override UIView ViewForPreview(UIDocumentInteractionController controller)
{
return _controller.View;
}
}
参考