I am attempting to load an image (.png) into the backgroundView of a UITableViewCell. However, the image is not displaying. Based on log outputs of the image returning NULL, it seems to be an issue of initializing the image.
Things I have tried/checked:
The filename is spelled and capitalized correctly.
The file was appropriately added to Xcode and is visible in Copy Bundle Resources
The file's Target Membership box is checked in the File Inspector
I updated the file, so to be sure, I deleted app from the simulator as well as the contents of the DerivedData folder.
I restarted XCode.
I tried loading the image via:
[UIImage imageNamed:@"cell-bg.png"]
as well as
[UIImage imageNamed:@"cell-bg"]
I also tried loading from the bundle:
NSBundle *mainBundle = [NSBundle mainBundle]; NSString *imagePath = [mainBundle pathForResource:@"cell-bg" ofType:@"png"]; NSLog(@"path: %@", imagePath); UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
For this last one, the NSLog produces a full path in the output, but when I perform another NSLog for image
it returns NULL
.
Apple's UIImage Class Reference states under the -imageWithContentsOfFile:
method:
Return Value A new image object for the specified file, or nil if the method could not initialize the image from the specified file.
So, could there be something wrong with the file? How could I diagnose and correct the issue?