I’m having problem displaying UIImage in UIImageView. I looked all over stackoverflow for similar questions, but none of the fixes helped me.
- The image is indeed in my bundle
- File Inspector -> Target Membership is checked for the image
- IBOutlet is connected (I have tried both using IBOutlet and doing it programmatically)
- Both png nor jpg works
Here’s the code for using Interface Builder –
//@property and @synthesize set for IBOutlet UIImageView *imageView
- (void)viewDidLoad
{
[super viewDidLoad];
NSAssert(self.imageView, @"self.imageView is nil. Check your IBOutlet connection");
UIImage *image = [UIImage imageNamed:@"banner.jpg"];
NSAssert(image, @"image is nil");
self.imageView.image = image;
}
This code will terminate with NSAssert, printing in the console that ‘image is nil’.
I also tried selecting the Image directly from the attributes inspector:

However it still doesn’t show the image (still terminates with NSAssert – ‘image is nil’).
Any help or suggestions will be greatly appreciated.
Thanks
See if you can get see the file in your code – use
I just typed this in but you get the idea – get the path using the first, make sure you got it, then ask the file manager to see if it exists. If it does you can read the file into a NSData object, then log the size, then see if you can create the image using imageWithData – if that fails then iOS may not be able to decompress it.
I often take images created in PhotoShop or elsewhere, load them in Preview, then save them before adding them to my projects. In general, if an Apple technology saves the image in whatever format you want (png, jpg, etc), then its likely that iOS can open it too.