iOS - QuickLook - How to open an object in QuickLook without a UIScrollView

11,171

I'm not sure how you plan to design your UI to open a file. I've used a few different ways, so I'll toss out some ideas. A UITableView is ideal for large amounts of files. A generic scroll view can also be used for a large number of files. I've used an alert view for an app that only generates one or two files. You could also use a view with document icons like the iPad Mail app. To get the document icons, use UIDocumentInteractionController. The WWDC 2010 DocInteraction sample code goes in great depth with how to use UIDocumentInteractionController.

As for opening the file, the Quick Look framework makes that easy. A simple, self-contained solution is to subclass QLPreviewController. Then, your subclass needs to conform to the QLPreviewControllerDataSource protocol and optionally the QLPreviewControllerDelegate protocol. Next, pass it an array of NSURLs pointing to your files. You can do this either through an initializer like -initWithFiles:(NSArray *)files or through a setter. From here, -previewController:previewItemAtIndex: just needs to index into the array to get the appropriate file to show. -numberOfPreviewItemsInPreviewController: just needs to return the size of the array. Once you have this class finished, you can use any UI design you like to push this view or present it modally.

Hopefully this is more clear than my tutorial you've been reading.

EDIT:

I have posted some code to Github that may help you. I have created a file previewer class as described above. I also posted a demo app that directly uses a QLPreviewController.

Share:
11,171
Mytheral
Author by

Mytheral

I am myself.

Updated on June 05, 2022

Comments