Search code examples
iphonepdfquicklook

Problem in implementing Quick Look API


I want to implement QuickLook API for preview of pdf file. I made a view based app and in .h file I import QuickLook/QuickLook.h . in .m file I made the object of QLPreviewController inside viewDidLoad. After that i tried to make object of QLPreviewItem, but this gives error "QLPreviewItem undeclared". Plz help me if u can.

Thanx.


Solution

  • Your almost there!

    the QLPreviewController need a QLPreviewControllerDataSource

    implement <QLPreviewControllerDataSource>

    and add two functions:

    - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
    {
        return 1; //number of documents, usually you use a array with document url's
    }
    
    - (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index
    {
        return [NSURL fileURLWithPath:@"document.pdf"]; //other documents are supported too
    }
    

    Your see that the second method a QLPreviewItem returns (as you see it works with plain URL's too)

    I hope I helped you a bit further