在我的应用程序中,我必须存储一些数据,为此,我使用了NSHomeDirectory
并将数据与documents文件夹一起存储到其中。
即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。
最佳答案
在上面的代码中更改
-(void)setUpTheFileNamesToBeListed{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
}
对此
-(void)setUpTheFileNamesToBeListed{
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingString:@"/Documents/"];
filePathsArray = [[NSFileManager defaultManager] subpathsOfDirectoryAtPath:documentsDirectory error:nil];
}
关于iphone - 在UITableView中显示NSHomeDirectory()的保存文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13138130/