Quicklook 支持的文件:
- iWork文档
- 微软Office97以上版本的文档
- RTF文档
- PDF文件
- 图片文件
- 文本文件和CSV文件
首先需要加入framework:
然后加入头文件:
#import <QuickLook/QuickLook.h>
在需要进入快速查看的地方初始化(这里只显示一个文件):
local_file_URL = [NSURL fileURLWithPath:path];
QLPreviewController *ql = [[[QLPreviewController alloc]initWithNibName:nil bundle:nil] autorelease];
ql.navigationController.navigationBarHidden = YES;
// Set data source
ql.dataSource = self;
// Which item to preview
[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;
// Push new viewcontroller, previewing the document
[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;
}