如果是从文件目录尝试retrive图像唯一的问题:
[UIimage imageWithContentsOfFile:yourFilePath];
//你可以使用这些方法来检索文件路径
- (NSString *) rootPath{
return [NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) lastObject];
}
- (NSString *) pathFoResourse : (NSString *) resourseName ofType: (NSString *)type{
NSString *path = [[self rootPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.%@", resourseName, type]];
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
path = [[NSBundle mainBundle] pathForResource:resourseName ofType:type];
}
NSLog(@"**path:%@**", path);
return path;
}
你所建议的不是取代默认的imageNamed。但由此我甚至不需要在UIImage上的类别,因为imageNamed是类方法,而不是实例方法。我所需要的就是一个来自特定路径的UIImage,它可以从我自己的类方法中返回。不必在UIImage上。但是我正在寻找一些更优雅的方法,以最好的方式挤压OOPS。正如我在发布的链接中所显示的那样,这并不罕见。无论如何感谢您的投入。 – 2013-02-28 05:29:18
你说得对。如果打晕,imageNamed中确实存在未公开的错误。我在dealloc上崩溃了。 – mafonya 2014-08-28 11:08:56