Ank
Ank

Reputation: 514

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.

Upvotes: 1

Views: 1872

Answers (2)

Justin
Justin

Reputation: 2999

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

Upvotes: 2

Julien
Julien

Reputation: 3477

QLPreviewItem is not a class but a protocol. You must either use NSURLs to fill the API (NSURL conforms to QLPreviewItem) or create your own class of objects conforming to that protocol.

Upvotes: 4

Related Questions