How to Disable QLPreviewController print Button

ricardo somarriba picture ricardo somarriba · Aug 2, 2011 · Viewed 13.6k times · Source

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

Answer

rbrown picture rbrown · Aug 3, 2011

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.