私のアプリでは、いくつかのデータを保存する必要があります。その目的のためにNSHomeDirectory
、ドキュメントフォルダーを使用してデータを保存しました。すなわち
NSString *filename = [[[URL1 path] lastPathComponent] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *Path=[NSHomeDirectory() stringByAppendingString:@"/Documents/"];
result=[Path stringByAppendingString:filename];
今、私はこのデータを UITableView に表示したいのですが、どのようにそれが可能であり、これについて検索して知りましたNSDocumentDirectory
.. NSHomeDirectory はこれとどう違うのですか?? 私はこの答えを得ました
-(void)setUpTheFileNamesToBeListed{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [filePathsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Insert this line to add the file name to the list
cell.textLabel.text = [documentsDirectory stringByAppendingPathComponent:[filePathsArray objectAtIndex:indexPath.row]];
}
これは私が得たものです..しかし、それが私にとってどのように機能するか..NSHomeDirectoryの場合。