iOS - 通过 Quicklook 打开 PDF,而不使用 UIScrollView
我正在尝试通过 QuickLook 框架打开 PDF,而不使用 UIScrollView...
我相信我错过了一些东西...
我认为我出错的地方是我需要使用 QLPreviewController 并且 QLPreviewController 上是一个数据源必须符合 QLPreviewItem。该文档指出 NSURL 确实符合 QLPriewItem,因此我将 Preview.dataSource 设置为引发错误的 NSURL:
[NSURL numberOfPreviewItemsInPreviewController:]: 无法识别的选择器发送到实例
终止应用程序由于未捕获异常'NSInvalidArgumentException',原因:'-[NSURL numberOfPreviewItemsInPreviewController:]:无法识别的选择器发送到实例 0x5b5f200'
这让我认为 NSURL 不符合要求。
我认为所有的代码都是必要的......
- (BOOL)previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id <QLPreviewItem>)item {
return YES;
}
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {
return [documents count];
}
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {
return [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[documents objectAtIndex:index] ofType:nil]];
}
- (void)pushPDF {
QLPreviewController *preview = [[QLPreviewController alloc] init];
preview.dataSource = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MCIT_Quiz" ofType:@"pdf"]];
//preview.currentPreviewItemIndex = 0;
[self presentModalViewController:preview animated:YES];
[preview release];
}
I am trying to open a PDF via the QuickLook framework without using UIScrollView...
I believe I'm missing something...
Where I believe I'm going wrong is that I need to use a QLPreviewController and on the QLPreviewController is a dataSource that has to conform to QLPreviewItem. The documentation states that NSURL does conform to QLPriewItem so I'm setting the preview.dataSource to an NSURL which is throwing an error:
[NSURL numberOfPreviewItemsInPreviewController:]: unrecognized selector sent to instance
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL numberOfPreviewItemsInPreviewController:]: unrecognized selector sent to instance 0x5b5f200'
Which makes me think that NSURL does not conform.
all the code I think is necessary...
- (BOOL)previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id <QLPreviewItem>)item {
return YES;
}
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller {
return [documents count];
}
- (id <QLPreviewItem>) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index {
return [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[documents objectAtIndex:index] ofType:nil]];
}
- (void)pushPDF {
QLPreviewController *preview = [[QLPreviewController alloc] init];
preview.dataSource = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"MCIT_Quiz" ofType:@"pdf"]];
//preview.currentPreviewItemIndex = 0;
[self presentModalViewController:preview animated:YES];
[preview release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终只是创建了另一个类来保存我的值并用作数据源,有点快速和肮脏,但它有效。
插入文本来分解文件
I ended up just creating another class to hold my values and use as a datasource, a bit quick and dirty but it works.
inserting text to break up the files
好吧,我没有看到 NSURL 哪里符合 QLPreviewControllerDataSource。我想你想要
然后你已经编写的例程(numberOfPreviewItemsInPreviewController和previewController)将返回适当的NSURL(尽管不清楚“文档”是如何填充的。)。
Well, I don't see where an NSURL conforms to QLPreviewControllerDataSource. I think you want
And then your already written routines (numberOfPreviewItemsInPreviewController and previewController) would return the appropriate NSURL (although it's not clear how "documents" gets filled.).