2010-12-08 69 views
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]; 

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

/用户/ PHH /库/应用程序支持/ iPhone模拟器/ 4.2 /应用/ 3DAB4772-7251-4E39-8EA8-4AFE32DFB61A/MyApp.app/words/001/001-1.png

但是UIImage总是零?我只是不知道这里发生了什么......

帮助....?

由于

+0

? – WaiLam 2010-12-08 08:42:07

+0

你的文字和001文件夹是蓝色的吗? – 2010-12-08 08:54:22

回答

1

imageWithContentsOfFile:为返回值是

为指定 文件的新图像对象,或零如果该方法不能 初始化从 指定的文件图像。

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

1

你在哪里得到的图像是零尝试了这一点,而在图像上传递给我

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

编码快乐......