如果NSBundle你找到的是你想要的:
NSBundle *yourTargetBundle = [NSBundle mainBundle];
or
NSBundle *yourTargetBundle = [NSBundle bundleWithURL:[[NSBundle mainBundle]
URLForResource:@"YourCustomBundleName" withExtension:@"bundle"]];
并得到 nil 结果使用函数:pathForResource: ofType:. 然后你可以在paths下面记录资源yourTargetBundle:
// Given that your resource type is .png and have no sub dir
NSArray *resoursePaths = [yourTargetBundle pathsForResourcesOfType:@"png" inDirectory:nil];
NSLog(@"resoursePaths == %@",resoursePaths);
它将记录类型的所有资源路径png。您可以获得image对象使用:
targetImg = [[UIImage alloc] initWithContentsOfFile:@"OnePngPathYouChose"];
我认为上述方法是解决这种return nil情况的一种方法。