现在我的应用程序有一个蓝色参考文件夹,该应用程序可以加载图像。\
代码如下:
NSString *bundelPath = [[NSBundle mainBundle] pathForResource:@"YSPSdk" ofType:@"bundle"];
NSBundle *sdkBundle = [NSBundle bundleWithPath:bundelPath];
for (int i = 1; i <= 72; i++)
{
NSString *imageName = [NSString stringWithFormat:@"adapte_animation_%03d@3x",i];
NSString *imagePath = [sdkBundle pathForResource:imageName ofType:@"png" inDirectory:@"Loading"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
[_imageArray addObject:image];
}
该应用程序的构建和运行良好。
然后,我将一些新图像添加到该文件夹中,并如下更改代码:
for (int i = 1; i <= 12; i++)
{
NSString *imageName = [NSString stringWithFormat:@"animation_%03d",i];
NSString *imagePath = [sdkBundle pathForResource:imageName ofType:@"png" inDirectory:@"Loading"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
[_imageArray addObject:image];
}
该应用程序将崩溃。
然后我调试了这个应用程序,并在代码中设置了一个断点。
我看到未创建图片。
为什么?
我必须用新图像替换旧图像。
在这种情况下有什么补救办法?
==============
我重命名了一些旧图像,然后编辑代码以加载此新名称的旧图像。 我运行该应用程序,该应用程序显示了相同的错误:
找不到imagePath!
答案 0 :(得分:0)
在我的主要项目中。目标->构建阶段->复制捆绑资源。
我删除了YSPSdk.bundle
,然后再次添加。我解决了这个问题。