【发布时间】:2012-01-27 23:39:04
【问题描述】:
我的图片(.png)无法显示。
我检查它是否存在于我使用的路径中,并且确实存在。但是没有图像出现。
这是我一直在尝试的:
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *outputPath = [documentsDir stringByAppendingPathComponent:[fileList objectAtIndex:indexPath.row]];
NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
NSString *imgPath = [[outputPath stringByReplacingOccurrencesOfString:@"mov" withString:@"png"]retain];
if ([fileManager fileExistsAtPath:imgPath])
{
NSLog(@"FOUND IMG");
NSLog(imgPath);
}
NSData *imgData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imgPath]];
UIImage *thumbNail = [[UIImage alloc] initWithData:imgData];
UIImageView * imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
[imgView setImage:thumbNail];
[cell addSubview:imgView];
[imgView release];
确认文件存在的调试输出
FOUND IMG
2011-12-26 12:42:23.066 iGeo2[412:707] /var/mobile/Applications/1A2B0D85-CDB1-4E4B-
9509-EF68B1A0E720/Documents/0.009000.png
我有点困惑。有人看到我在哪里犯了错误吗?
非常感谢, -代码
我尝试了其他几种方法,但都没有出现。
【问题讨论】:
-
您可以在这里得到答案:stackoverflow.com/questions/6663511/…
-
要使用
NSFileManager简单地使用说服方法:NSFileManager *fileManager = [NSFileManager defaultManager]通常检查文档以了解基于类的说服方法。如果可能的话,也使用 ARC,它确实使开发代码更简单。
标签: iphone objective-c ios xcode