UIDocumentInteractionController change title of presented view
Asked Answered
S

2

20

I am using the UIDocumentInteractionController to display PDF files. 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.

Is there any way to change the displayed title as presented by the UIDocumentInteractionController?

Scalenus answered 12/10, 2012 at 8:47 Comment(0)
T
44

UIDocumentInteractionController has a name property which you can set to your user-friendly name. That name will be used in the title bar of the presented document.

Tetrarch answered 12/10, 2012 at 9:34 Comment(2)
@RDC Can you show me sample code, as its not working for me.Payable
This solution does not work. It still shows the file name.Cns
D
0

This is Xamarin (C#) code, but I hope it helps anyways

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;
    }
}
Demitria answered 7/7, 2020 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.