现在的位置: 首页 > 综合 > 正文

QLPreviewController用法

2013年10月30日 ⁄ 综合 ⁄ 共 1408字 ⁄ 字号 评论关闭

从IOS4.0后,apple推出新的文件预览控件:QLPreveiewController,已经支持pdf文件阅读。

用法:

1.实现QLPreviewControllerDataSource

 

Cpp代码  收藏代码
  1. #import <Foundation/Foundation.h>  
  2. #import <QuickLook/QuickLook.h>  
  3.   
  4.   
  5. @interface PreviewDataSource : NSObject<QLPreviewControllerDataSource> {  
  6.     NSString *path;   
  7. }   
  8.   
  9. @property (nonatomic, assign) NSString *path;   
  10.   
  11. @end  
  12. #import "PreviewDataSource.h"  
  13.   
  14.   
  15. @implementation PreviewDataSource  
  16.   
  17. @synthesize path;   
  18.   
  19.   
  20. - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller   
  21. {  
  22.     return 1;  
  23. }  
  24.   
  25.   
  26. - (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index   
  27. {  
  28.   
  29.     return [NSURL fileURLWithPath:path];  
  30. }  
  31.   
  32.   
  33.   
  34. - (void)dealloc {   
  35.     [path release];   
  36.     [super dealloc];   
  37. }   
  38. @end  

 2.调用方法:

 

Cpp代码  收藏代码
  1. QLPreviewController *previewoCntroller = [[[QLPreviewController alloc] init] autorelease];  
  2.                  
  3.                    PreviewDataSource *dataSource = [[[PreviewDataSource alloc]init] autorelease];  
  4.                    dataSource.path=[[NSString alloc] initWithString:appFile];  
  5.                    previewoCntroller.dataSource=dataSource;  
  6.                    [app.nav pushViewController: previewoCntroller animated:YES];  
  7.                    [previewoCntroller setTitle:fileName];  
  8.                    previewoCntroller.navigationItem.rightBarButtonItem=nil;

原文地址:http://wanggp.iteye.com/blog/1129059

【上篇】
【下篇】

抱歉!评论已关闭.