Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Disable QLPreviewController print Button

Can anyone tell me how to remove the QLPreviewController print button? Also would like to disable cut/paste/copy.

like image 828
ricardo somarriba Avatar asked Aug 02 '11 20:08

ricardo somarriba


4 Answers

UPDATE:

This no longer works in iOS 6. Quick Look runs in another process using XPC. See [here][3] for more details. I don't foresee any way to customize QLPreviewController. The following answer remains for anyone interested for pre-iOS 6.


If you want to simply remove the action button you need to subclass QLPreviewController. Then in -viewWillAppear: you need to remove the action button by calling [[self navigationItem] setRightBarButtonItem:nil]; This will also remove the ability to share files with other apps. If you are fine with that loss, then that's the easiest solution. One thing to be aware of is that QLPreviewController is NOT intended to be customized. You can check out this repository on Github. It contains a QLPreviewController that is already safely subclassed. You just need to add the one line to remove the action button. The repo also has some other conveniences.

The better but more complicated solution is to use UIDocumentInteractionController. From what I understand of QLPreviewController is that it's built using UIDocumentInteractionController. QLPreviewController was made for general use and easy addition. UIDocumentInteractionController gives much more control, but is harder to use. I can't sufficiently describe how to use it here. I recommend checking out WWDC 2010 session 106 Understanding Document Interaction Controller.

As for disabling cut/copy/paste, you can't do that with QLPreviewController. You might be able to do that with UIDocumentInteractionController, but I wouldn't count on it. Depending on what files you want to display, you may be able to do a completely custom implementation, but that's a lot of work. It's relatively easy to make viewers for plain text, photos, videos, and PDFs. Office documents are more effort than it's worth.

EDIT:

I've built the ability to remove the action button right into RBFilePreviewer so you don't have to worry about doing it yourself.

like image 97
rbrown Avatar answered Nov 16 '22 05:11

rbrown


If you subclass QLPreviewController and then add this one method:

-(void)viewDidAppear:(BOOL)animated{

    [[self navigationItem] setRightBarButtonItem:nil]; 
}

in the subclass, the action button will disappear as rbrown notes above. This will not work if you use viewWillAppear. Also, an unexpected side-effect of doing this is that the toolbar on the preview now appears at all times, instead of just when you tap the view.

like image 21
millport Avatar answered Nov 16 '22 04:11

millport


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self navigationItem].rightBarButtonItems = nil;
}

Works for me instead of [[self navigationItem] setRightBarButtonItem:nil];

like image 2
Andrea Leganza Avatar answered Nov 16 '22 04:11

Andrea Leganza


I also need to custom the navigaiton item of QLPreviewController. Just like rbrown said, XPC is used and we can no longer add custom items in viewDidLoad or viewWillAppear.

Currently I use this way:

  1. create a new class of UIViewController
  2. add the view of QLPreviewController to the new class

It seems wired but works.

like image 1
scorpiozj Avatar answered Nov 16 '22 03:11

scorpiozj