从IOS4.0后,apple推出新的文件预览控件:QLPreveiewController,已经支持pdf文件阅读。
用法:
1.实现QLPreviewControllerDataSource
- #import <Foundation/Foundation.h>
- #import <QuickLook/QuickLook.h>
- @interface PreviewDataSource : NSObject<QLPreviewControllerDataSource> {
- NSString *path;
- }
- @property (nonatomic, assign) NSString *path;
- @end
- #import "PreviewDataSource.h"
- @implementation PreviewDataSource
- @synthesize path;
- - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
- {
- return 1;
- }
- - (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
- {
- return [NSURL fileURLWithPath:path];
- }
- - (void)dealloc {
- [path release];
- [super dealloc];
- }
- @end
2.调用方法:
- QLPreviewController *previewoCntroller = [[[QLPreviewController alloc] init] autorelease];
- PreviewDataSource *dataSource = [[[PreviewDataSource alloc]init] autorelease];
- dataSource.path=[[NSString alloc] initWithString:appFile];
- previewoCntroller.dataSource=dataSource;
- [app.nav pushViewController: previewoCntroller animated:YES];
- [previewoCntroller setTitle:fileName];
- previewoCntroller.navigationItem.rightBarButtonItem=nil;