| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- //
- // LocalDocumentsViewController.m
- // Apex Mobile
- //
- // Created by Ray on 14-5-5.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "LocalDocumentsViewController.h"
- @interface LocalDocumentsViewController ()
- @end
- @implementation LocalDocumentsViewController
- - (BOOL)shouldAutorotate
- {
- return YES;
- }
- - (NSUInteger)supportedInterfaceOrientations
- {
- return UIInterfaceOrientationMaskPortrait;
- }
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
- {
- return UIInterfaceOrientationPortrait;
- }
- -(void)initpanel
- {
-
- self.toolsinfo = [[NSMutableArray alloc] init];
- NSMutableDictionary* map = [[NSMutableDictionary alloc] init];
-
-
- NSFileManager *manager;
- manager = [NSFileManager defaultManager];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [paths objectAtIndex:0];
- NSDirectoryEnumerator *direnum;
- direnum = [manager enumeratorAtPath: path];//枚举home下的目录
- NSLog(@"home=%@,direnum=%@",path,direnum);
- NSMutableArray *files;
- files = [NSMutableArray arrayWithCapacity:5];
- NSString *filename;
- while (filename = [direnum nextObject])
- {
- if ([[filename pathExtension] isEqualToString:@"pdf"])
- {
- [map setValue:filename forKey:@"title"];
- // [map setValue:@"rect_search_documents" forKey:@"img"];
- [self.toolsinfo addObject:map.copy];
-
- [files addObject: filename];
- NSLog (@"%@", filename);
- }
- }
- // NSEnumerator *fileenum;
- // fileenum = [files objectEnumerator];//枚举数组files
- // while (filename = [fileenum nextObject]) {
- // NSLog (@"%@", filename);
- // }
- //
-
-
-
-
-
-
-
-
- //
- //
- // [map setValue:@"View document" forKey:@"title"];
- // [map setValue:@"rect_view_download_documents" forKey:@"img"];
- // [self.toolsinfo addObject:map.copy];
- //
-
- }
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self initpanel];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
-
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
-
- return self.toolsinfo.count;
-
-
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- DebugLog(@"cellForRowAtIndexPath");
-
- NSString *CellIdentifier = @"documentitem";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSString* title = [self.toolsinfo[indexPath.row] valueForKey:@"title"];
-
-
- // cell.accessoryView
- // UIImageView* iv= [[UIImageView alloc] initWithImage:];
- cell.textLabel.text = title;
- // cell.imageView.image = [UIImage imageNamed:[self.toolsinfo[indexPath.row] valueForKey:@"img"]];
-
- return cell;
-
-
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [paths objectAtIndex:0];
- NSString* filename =[self.toolsinfo[indexPath.row] valueForKey:@"title"];
-
- NSString *filePath = [path stringByAppendingPathComponent:filename];
- [self openFile:filePath];
-
- // NSFileManager *manager;
- // manager = [NSFileManager defaultManager];
- //
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *path = [paths objectAtIndex:0];
- // NSString* filename =[self.toolsinfo[indexPath.row] valueForKey:@"title"];
- //
- // NSString *filePath = [path stringByAppendingPathComponent:filename];
- //
- //
- //
- // PdfViewController *ViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PdfViewController"];
- // ViewController.filepath = filePath;
- // // ViewController. = self.function_name;
- // // ViewController.behavior =BEHAVIOR_SEARCH;
- //
- // [self.navigationController pushViewController:ViewController animated:YES];
-
- // SearchViewController *searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NewsView"];
- // searchViewController.function_name = @"Download Document";
- // [self.navigationController pushViewController:searchViewController animated:YES];
- // return;
-
- // NSString* title = [self.toolsinfo[indexPath.row] valueForKey:@"title"];
- // if([title isEqualToString:@"Search documents"])
- // {
- // SearchViewController *searchViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SearchViewController"];
- // searchViewController.function_name = @"Download Document";
- // [self.navigationController pushViewController:searchViewController animated:YES];
- // }
- // else if([title isEqualToString:@"View document"])
- // {
- // LocalDocumentsViewController *viewcontroller=[self.storyboard instantiateViewControllerWithIdentifier:@"LocalDocumentsViewController"];
- // // viewcontroller.module_name = @"Announcements";
- // [self.navigationController pushViewController:viewcontroller animated:YES];
- // }
-
- }
- //-(void)tableView:(UITableView *)tableView1 accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{
- //
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- // NSString *path = [paths objectAtIndex:0];
- // NSString* filename =[self.toolsinfo[indexPath.row] valueForKey:@"title"];
- //
- // NSString *filePath = [path stringByAppendingPathComponent:filename];
- // [self openFile:filePath];
- //
- //// NSURL *url = [[NSURL alloc] initFileURLWithPath:filePath];
- ////
- //// UIDocumentInteractionController *documentController =[UIDocumentInteractionController interactionControllerWithURL: url];
- //// documentController.delegate = self;
- //// [documentController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
- ////
- //// return;
- //
- //// NSURL *url = [[NSURL alloc] initFileURLWithPath:filePath];
- //// UIDocumentInteractionController *documentController =[UIDocumentInteractionController interactionControllerWithURL: url];
- ////
- //// return;
- //}
- -(void)openFile: (NSString *) file_url {
-
- NSURL *file_URL = [NSURL fileURLWithPath:file_url];
-
- if (file_URL != nil) {
- if (self.fileInteractionController == nil) {
- //_fileInteractionController = [[UIDocumentInteractionController alloc] init];
- _fileInteractionController = [UIDocumentInteractionController interactionControllerWithURL:file_URL];
- _fileInteractionController.delegate = self;
- // [_fileInteractionController retain];//不适用ARC,记得RETAIN 使用ARC注释这一行
- }
- else {
- self.fileInteractionController.URL = file_URL;
- }
-
- // [self.fileInteractionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES];
- [self.fileInteractionController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
- // [self.fileInteractionController presentPreviewAnimated:YES];
-
- }
- }
- #pragma mark methods for the UIDocumentInteractionControllerDelegate
- - (void)previewDocumentWithURL:(NSURL*)url
- {
- UIDocumentInteractionController* preview = [UIDocumentInteractionController interactionControllerWithURL:url];
- preview.delegate = self;
- [preview presentPreviewAnimated:YES];
- }
- - (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller
- {
- }
- - (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
- return self;
- }
- - (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller{
- return self.view.frame;
- }
- - (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller{
- return self.view;
- }
- @end
|