#import <QuickLook/QuickLook.h>
@interface ViewController ()<QLPreviewControllerDataSource,QLPreviewControllerDelegate>
@property (nonatomic, strong)QLPreviewController *QLPreVC;
- (void)viewDidLoad
{
[super viewDidLoad];
_QLPreVC=[QLPreviewController new];
_QLPreVC.dataSource=self;
_QLPreVC.delegate=self;
}
//代理方法
- (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) controller
{
return 3;//显示页数
}
- (id <QLPreviewItem>)previewController: (QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
//方法一:打开本地存储文件
NSURL *targetURL = [NSURL URLWithString:_url];
NSString *docPath = [self documentsDirectoryPath];
// Combine the filename and the path to the documents dir into the full path
NSString *pathToDownloadTo = [NSString stringWithFormat:@"%@/%@", docPath, [targetURL lastPathComponent]];
NSLog(@"-========--%@---",pathToDownloadTo);
BOOL hasPDF=NO;
NSFileManager *fileManager = [NSFileManager defaultManager];
hasPDF = [fileManager fileExistsAtPath:pathToDownloadTo];
targetURL = [NSURL fileURLWithPath:pathToDownloadTo];
//方法二:打开url链接
// NSURL *targetURL = [NSURL URLWithString:@"file:///Users/mac/Downloads/doc-previewer/Core%20J2ME%20Technology.pdf"];
return targetURL;
}
//最后只要在触发事件里面push即可:
- (void)nextpage_showFiles {
[self.navigationController pushViewController:_QLPreVC animated:YES];
}