tableView にファイルのリストを表示する mutableArray があります。これらのファイルをディレクトリに保存しました。
NSfileManager
クラスとメソッドを使用しattributesOfItemAtPath
て、fileSize、fileType などのファイルのプロパティを取得しています。
第2段階では、tableViewに触れたときに特定のファイルのプロパティを表示するdetailViewコントローラーを用意しようとしています。
問題は、fileSize や fileType などのプロパティを個別にバインドしてNSDictionary
、その特定のファイルの detailView に表示する方法がわからないことです。
ファイルを一覧表示し、プロパティを一覧表示するためのソース コードを次に示します。
- (void)listFiles {
NSFileManager *fm =[NSFileManager defaultManager];
NSError *error = nil;
NSString *parentDirectory = @"/Users/akilan/Documents";
NSArray *paths = [fm contentsOfDirectoryAtPath:parentDirectory error:&error];
if (error) {
NSLog(@"%@", [error localizedDescription]);
error = nil;
}
directoryContent = [[NSMutableArray alloc] init];
for (NSString *path in paths){
NSString *documentsDirectory = [[path lastPathComponent] stringByDeletingPathExtension];
[directoryContent addObject:documentsDirectory];
}
}
-(void) willProcessPath {
NSString *parentDirectory = @"/Users/akilan/Documents";
NSArray *paths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:parentDirectory error:nil];
for (NSString *path in paths){
filesPath = [parentDirectory stringByAppendingPathComponent:path];
NSDictionary *attrDir = [[NSFileManager defaultManager]attributesOfItemAtPath:filesPath error:nil];
filesSize = [attrDir objectForKey:NSFileSize];
filesName = (NSString *)directoryContent;
filesType = [path pathExtension];
createdDate = [attrDir objectForKey:NSFileCreationDate];
modifiedDate = [attrDir objectForKey:NSFileModificationDate];
}
}
次のステップに進むのを手伝ってください..よろしくお願いします..