本文主要是介绍关于Quicklook 以及 QLPreviewController,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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 sourceql.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;
}
这篇关于关于Quicklook 以及 QLPreviewController的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!