你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> 獲取本地文件列表及預覽文件

獲取本地文件列表及預覽文件

編輯:IOS開發綜合

好像QQ中收到的文件一樣,支持用其他使用翻開文件

思緒:先用tableView加載顯示本地文件,在用文件選擇器完成預覽文件的效果。。

中心代碼如下:

NSFileManager *fileManager = [NSFileManager defaultManager];
//在這裡獲取使用順序Documents文件夾裡的文件及文件夾列表
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docDirs = [paths objectAtIndex:0];
NSError *error = nil;

//_dataFileArray是包括有該文件夾下一切文件的文件名及文件夾名的數組
_dataFileArray = [fileManager contentsOfDirectoryAtPath:docDirs error:&error];
fileList = [NSMutableArray array];
XCPFileObject *fileObj;
for (NSString *name in _dataFileArray) {
fileObj = [[XCPFileObject alloc] init];
fileObj.fileName = name;
NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:[docDirs stringByAppendingPathComponent:name] error:nil];
fileObj.filemTime = [fileAttributes objectForKey:@"NSFileCreationDate"];
fileObj.fileSize = [[fileAttributes objectForKey:@"NSFileSize"] integerValue];
fileObj.fileOwner = [fileAttributes objectForKey:@"NSFileGroupOwnerAccountName"];

[fileList addObject:fileObj];
}

//列出給定一個文件夾裡的一切子文件夾名
NSMutableArray *dirArray = [[NSMutableArray alloc] init];
BOOL isDir = NO;

for (NSString *file in _dataFileArray) {
NSString *path = [docDirs stringByAppendingPathComponent:file];
[fileManager fileExistsAtPath:path isDirectory:(&isDir)];
if (isDir) {
[dirArray addObject:file];
}
isDir = NO;
}

原文Dome:http://download.csdn.net/detail/xcp_123/9735844

github地址:https://github.com/XiaCuiPing/XCP_FileView

在github的請點一下star支持哦,謝謝!

注:本文版權歸作者一切,轉載請注明出處

【獲取本地文件列表及預覽文件】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved