0

我已经在我的资源包中添加了一个资源(蓝色文件夹),甚至在我使用 NSFileManger 来确定文件是否存在以及它是否打印出检查中使用的完整路径时,一切似乎都很好。 :

NSString *p = [NSString stringWithFormat:@"%@/words/001", 
   [[NSBundle mainBundle] resourcePath]];

NSFileManager *fm = [NSFileManager defaultManager];

NSString *a = [p stringByAppendingPathComponent:@"001-1.png"];

UIImage *i;

if ([fm fileExistsAtPath:a]) {

  NSLog(@"file found ... %@", a);

  i = [UIImage imageWithContentsOfFile:a];
}
else {

  NSLog(@"doh!");
} 

[iv setImage:i];

我从文件存在检查中得到这个输出

/Users/phh/Library/Application Support/iPhone Simulator/4.2/Applications/3DAB4772-7251-4E39-8EA8-4AFE32DFB61A/MyApp.app/words/001/001-1.png

但 UIImage 总是为零?我只是看不到这里发生了什么......

帮助....?

谢谢

4

2 回答 2

1

在将图像传递给 i 时尝试一下

 i = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"001-1.png" ofType:@"png" inDirectory:@"word/001"];

快乐的编码...

于 2010-12-08T08:58:36.777 回答
1

imageWithContentsOfFile:的返回值为

指定文件的新图像对象,如果方法无法从指定文件初始化图像,则为 nil。

您确定该位置的文件是有效的图像文件吗?

于 2010-12-08T08:43:10.920 回答