`
wanggp
  • 浏览: 147727 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

QLPreviewController用法

阅读更多

从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;

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics