简体   繁体   English

UIDocumentInteractionController 更改呈现视图的标题

[英]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.

相关问题 设置显示视图的标题 - set title of presented view UIDocumentInteractionController可以在SplitView中显示吗? - Can UIDocumentInteractionController be presented in SplitView? 从显示的视图中更改UITableViewCell的属性 - Change UITableViewCell's properties from the presented view 更改 swift 中显示的视图控制器列表,例如 - Change a list of presented view controllers in swift like iOS-UIDocumentInteractionController并添加视图 - iOS - UIDocumentInteractionController and adding a view 具有自己的视图的UIDocumentInteractionController - UIDocumentInteractionController with own view 更改UIDocumentInteractionController上的NavigationBar背景 - Change NavigationBar background on UIDocumentInteractionController Presented View Controller中的方向更改未更新父View Controller - Orientation change in Presented View Controller not updating Parent View Controller UIDocumentInteractionController 注释属性不会将标题复制到呈现的应用程序 - UIDocumentInteractionController annotation property doesn't copy caption to presented application 从UIViewController方法更改UIWindow的显示视图 - Change UIWindow's presented view from UIViewController method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM