http://blog.csdn.net/reylen/article/details/8534951
Quicklook 支持的文件:
- iWork文档
- 微软Office97以上版本的文档
- RTF文档
- PDF文件
- 图片文件
- 文本文件和CSV文件
首先需要加入framework:
![](https://img-my.csdn.net/uploads/201301/23/1358931780_1077.png)
然后加入头文件:
- #import <QuickLook/QuickLook.h>
在需要进入快速查看的地方初始化(这里只显示一个文件):
- local_file_URL = [NSURL fileURLWithPath:path];
- QLPreviewController *ql = [[[QLPreviewController alloc]initWithNibName:nil bundle:nil] autorelease];
- ql.navigationController.navigationBarHidden = YES;
-
- ql.dataSource = self;
-
-
- [ql setCurrentPreviewItemIndex:0];
-
- navigationController = [[[UINavigationController alloc]initWithRootViewController:ql] autorelease];
- UIBarButtonItem *backButton = [[UIBarButtonItem alloc]initWithTitle:@"back" style:UIBarButtonItemStylePlain target:self action:@selector(closeQuickLookAction:)];
- ql.navigationItem.leftBarButtonItem = backButton;
-
-
- [self presentModalViewController:navigationController animated:YES];
backButton的响应事件:
- - (IBAction)closeQuickLookAction:(id)sender {
- [navigationController dismissModalViewControllerAnimated:YES];
- }
数据源
- #pragma mark - quicklook
- - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
- {
- return 1;
- }
- - (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
- {
- return local_file_URL;
- }