我想实现 QuickLook API 来预览 pdf 文件。我制作了一个基于视图的应用程序,并在 .h 文件中导入 QuickLook/QuickLook.h 。在 .m 文件中,我在 viewDidLoad 中创建了 QLPreviewController 的对象。之后我尝试制作 QLPreviewItem 的对象,但这给出了错误“QLPreviewItem undeclared”。如果可以的话,请帮助我。
谢谢。
QLPreviewItem 不是一个类,而是一个协议。您必须使用 NSURL 来填充 API(NSURL 符合 QLPreviewItem)或创建您自己的符合该协议的对象类。
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