Question

How can I tell if an image is present in the main app bundle based on a string? For example, is there an image called image1.png in the bundle?

Était-ce utile?

La solution

NSBundle method:

- (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension

will return nil if no image was found.

i.e.

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image1" ofType@"png"];
if(filePath.length > 0 && filePath != (id)[NSNull null]) {
   UIImage *myImage = [UIImage imageWithContentsOfFile:filePath];
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top