gpt4 book ai didi

ios - NSFileManager 在文件夹中搜索图像文件

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

我正在使用 NSFileManager 搜索“index.png”文件。如果文件不存在,那么我将尝试显示默认图像。我正在使用下面的代码,但它不起作用。我在这里做错了什么吗?

NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString path1 = [[paths objectAtIndex:0] stringByAppendingPathComponent:literature.localURL.path];
path = [path1 stringByAppendingPathComponent:@"index.PNG"];

if ([[NSFileManager defaultManager] fileExistsAtPath:path]){
cell.preview = [UIImage imageWithContentsOfFile:path1];
}
else {
cell.preview = [UIImage imageNamed:@"Default-HTML5.PNG"];
}
}

最佳答案

您将路径设置为两个不同的东西。例如,对其中之一使用不同的字符串

NSString *path1 = [[paths objectAtIndex:0] stringByAppendingPathComponent:literature.localURL.path];

其他保持不变

并制作“index.PNG”“index.png”。 iOS 区分大小写。

关于ios - NSFileManager 在文件夹中搜索图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14617727/

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