[英]UIDocumentInteractionController change title of presented view
I am using the UIDocumentInteractionController
to display PDF files.我正在使用UIDocumentInteractionController
来显示 PDF 文件。 My files are stored in the filesystem using encoded filenames that are not user-friendly.我的文件使用对用户不友好的编码文件名存储在文件系统中。 I do have access to a more friendly name for the file, but the file is not stored with this name (for uniqueness reasons).我确实可以访问该文件的更友好名称,但该文件未使用此名称存储(出于唯一性原因)。
When I load the document into the UIDocumentInteractionController
then the view displays the unfriendly 'real' filename in the title bar.当我将文档加载到UIDocumentInteractionController
,视图会在标题栏中显示不友好的“真实”文件名。
Is there any way to change the displayed title as presented by the UIDocumentInteractionController
?有什么方法可以更改UIDocumentInteractionController
显示的标题吗?
UIDocumentInteractionController
has a name
property which you can set to your user-friendly name. UIDocumentInteractionController
有一个name
属性,您可以将其设置为您的用户友好名称。 That name will be used in the title bar of the presented document.该名称将用于所呈现文档的标题栏中。
This is Xamarin (C#) code, but I hope it helps anyways这是 Xamarin (C#) 代码,但我希望它有帮助
public class PreviewFile : IPreviewFile
{
public PreviewFile()
{
}
public void Preview(string file, string title)
{
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
bool isUrl = file.StartsWith("file:", StringComparison.OrdinalIgnoreCase);
var url = isUrl ? new NSUrl(file) : NSUrl.FromFilename(file);
var controller = UIDocumentInteractionController.FromUrl(url);
controller.Delegate = new MyInteractionDelegate(vc);
controller.Name = title;
controller.PresentPreview(true);
}
}
public class MyInteractionDelegate : UIDocumentInteractionControllerDelegate
{
UIViewController parent;
public MyInteractionDelegate(UIViewController controller)
{
parent = controller;
}
public override UIViewController ViewControllerForPreview(UIDocumentInteractionController controller)
{
return parent;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.