gpt4 book ai didi

iphone - 在 UITableView 中显示 NSHomeDirectory() 保存的文件

转载 作者:行者123 更新时间:2023-11-28 22:46:19 24 4
gpt4 key购买 nike

在我的应用程序中,我必须存储一些数据,为此我使用了 NSHomeDirectory 并将数据与文档文件夹一起存储到其中。即

NSString *filename = [[[URL1 路径] 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com