Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top