How can I remove the action button from UIDocumentInteractionController?

I don't want to save or share my Document with any other applications on the phone. So, How can I remove the action button from UIDocumentInteractionController?

Thanks in advance.

Posts

  • rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

    Don't do this, don't try it :-)

    UIDocumentInteractionController does not support this. Instead, use QLPreviewController. An example can be found here: http://www.michaelridland.com/xamarin/displaying-a-pdf-word-excel-rtf-images-in-xamarin-ios/

  • SatishBirajdarSatishBirajdar USMember ✭✭

    Thank you for the link.

    Could you please tell me how do I remove the action button (square with up arrow), shown on the top right on the Navigation Bar, since I only want the user to view the document / file / image in QLPreviewController ? Your prompt reply will be appreciated.

  • SatishBirajdarSatishBirajdar USMember ✭✭

    @rene_ruppert Thank you for the link.

    Could you please tell me how do I remove the action button (square with up arrow), shown on the top right on the Navigation Bar, since I only want the user to view the document / file / image in QLPreviewController ? Your prompt reply will be appreciated.

  • rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

    The solution is not to remove the button but to not use the navigation bar. I created a small example for you where the view of the QLPreviewController is added into the existing hierarchy instead of presenting the entire controller. Then you can build your own UI around it:

    https://gist.github.com/Krumelur/a10bd857060b99fb6e08

  • SatishBirajdarSatishBirajdar USMember ✭✭

    @rene_ruppert Thanks for the sample code, you are an awesome guy. :) This code worked fine for image files, but not for PDF files. Below I have attached a snippet:

                public override IQLPreviewItem GetPreviewItem (QLPreviewController controller, nint index)
                {
        //          string fileName = "Image01.jpg";
                    string fileName = "smallPDF.pdf";
    
                    NSUrl url = NSUrl.FromFilename (fileName);
    
                    if (File.Exists (fileName)) {
                        Console.WriteLine ("Filepath found.");
                    } else {
                        Console.WriteLine ("Filepath not found.");
                    }
                    return new QLItem ("Title", url);
                }
    

    After executing this code, the filepath for PDF does exists but it doesn't displays the document. And this link shows that QLPreviewController supports Images, Doc, PDF, etc. Could you please tell me the way of presenting PDF file in QLPreviewController.

    Thanks

  • rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

    I tried it and indeed, it does not work. I'm puzzled. A quick check with ObjectiveC shows that it is working there. I remember viewing PDFs, so I assume it is some bug. I'm afraid, I cannot help at the moment. If I find something, I'll let you know.

  • rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

    @SatishBirajdar Thanks to our iOS experts we managed to find the problem! I set up a rep where you can see a working solution that will allow you to present the complete QLPreviewController or to add its view to your own view hierarchy.

    https://github.com/Krumelur/QLPreviewControllerDemo

    The only change we had to make was to use var url = NSUrl.FromFilename(NSBundle.MainBundle.PathForResource ("pdf.pdf", null)); instead of var url = NSUrl.FromFilename("pdf.pdf");- iow, an absolute URL works, a relative one does not even thou the QLPreviewController obviously finds the file, since it shows the file size.

  • SatishBirajdarSatishBirajdar USMember ✭✭

    @rene_ruppert Thanks for the solution, will try this out.

  • SatishBirajdarSatishBirajdar USMember ✭✭

    @rene_ruppert Hey Rene, I have attached a demo app to explain the following case:

    1. Execute the application.
    2. Keep the simulator in Landscape Orientation.
    3. And now click on the "Click for SVC" button of the First Screen.
    4. Now you can see that the document doesn't resizes with the screen size.

    While the document resizes fine, when it is opened in portrait and then changed to landscape. Do you have any suggestion for this issue?

    Thanks

  • SatishBirajdarSatishBirajdar USMember ✭✭

    @rene_ruppert solved that issue by adding resizingmask to the view:

    UIView view = preview.View;
    view.AutoresizingMask = UIViewAutoresizing.FlexibleRightMargin | UIViewAutoresizing.FlexibleLeftMargin | UIViewAutoresizing.FlexibleBottomMargin | UIViewAutoresizing.FlexibleTopMargin;
    

    But now the navigationBar is overlapping the document. Any suggestion for preventing from overlapping ?

    Thanks

  • rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

    You should go and check out AutoLayout and Constraints on iOS. Better than AutoResizingMasks.

    I think you can set something like EdgesForExtendedLayout = None to prevent the nav bar from overlapping your content.

  • SatishBirajdarSatishBirajdar USMember ✭✭

    @rene_ruppert EdgesForExtendedLayout = None isn't working for me. And it seems like I cannot add QLPreviewController in .xib file, to add AutoLayout feature.

    Could you please provide a way to prevent from overlapping of the screen ?

    Thanks

  • SatishBirajdarSatishBirajdar USMember ✭✭

    Below I have attached the sample application, for you reference. Thanks.

  • SatishBirajdarSatishBirajdar USMember ✭✭

    Below I have attached the sample application, for you reference. Thanks.

Sign In or Register to comment.