Image not showing in UIImageView in Interface Builder / iPhone
Asked Answered
A

19

29

I have a UIView with an UIImageView dragged onto the view. All of a sudden, for all my xibs, the image no longer shows up. There is a blue X. However, when it builds, the image is there.

At one point, I deleted and regenerated all my images and moved some into a subfolder in Xcode. Normally, when you go to select an image for an UIImageView, IB allows you to pick from any image in the project. But, I can't see any of the images I had put in the folder anymore in the dropdown.

All I see in the dropdown on the Inspector is the one image I want, but that is also the one that is not showing up. And like I said, if I build it on the device or simulator, it all works.

There is some cache or something screwed up somewhere. Everything builds with no errors. I cleared the caches and rebuilt. It all works. No error or warnings. But...I can't see any other images and IB still thinks it's missing the image that is clearly selected in the dropdown.

So how do I get Xcode and IB back on track and see what assets it properly should be seeing in the XIBs?

Arri answered 16/4, 2010 at 3:15 Comment(1)
Did you try "clean all targets"?Moscow
C
21

Try cleaning and rebuilding the project.

If it's still not working then remove all images from Xcode (select delete reference only) and then re-add them again by dragging those images into Xcode. Then re-build it and it should work.

Contraoctave answered 16/4, 2010 at 5:26 Comment(1)
This helped. I have also noticed that sometimes I just have to quit Xcode and relaunch to clear up this problem. Sad!Jarvey
S
15

My recipé: CLEAN + Build + QUIT XCODE AND THEN REOPEN IT!

Voilá!! It's there!

Syncom answered 11/4, 2013 at 9:18 Comment(0)
W
10

Make sure you have added your image to target when dragging it into the project. Because Xcode's folder / group / project system is buggy, click on the image and check that it is actually added to the target build in the inspector as shown (a graphical problem deserves a graphic answer!) :

Add the image to the project...

enter image description here

Add to targets... (or so we think)

enter image description here

Background image shows nicely in Interface Builder...

enter image description here

But when we run, we have nothing but the background color we set... no image...

enter image description here

Clicking on the UIImageView in Interface Builder and using the inspector, we scroll down and find that in fact it was never added to the target like Xcode clearly showed in step 2...

enter image description here

So we add it to the target...

enter image description here

And we build and run and voila! Our image shows in the UIImageView exactly where it is suppose to show.

enter image description here

This drove me nuts for the better part of the day until I tried adding code to make it happen to see if it was a flakey image. I added it without issue by creating the the viewDidLoad implementation below.

Note that you don't need this if Xcode / Interface Builder is working the way it should. Either user IB or use this code, not both :

- (void)viewDidLoad {
UIColor *   theColor;
UIImage *   theImage;

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
theImage = [UIImage imageNamed:@"/<redacted>/background sea green gradent.png"];
theColor = [UIColor colorWithPatternImage: theImage ];
[self.view setBackgroundColor: theColor ]; }

Note: This can be the same issue if your button is not showing a custom image...

Wendolynwendt answered 7/8, 2017 at 14:5 Comment(1)
i had to click target membership in iOS 11 even though I checked that when I added the images. iOS 11 the greatest release of breaking things ever.Cannibalism
S
3

Just ran into this issue. Exported the identical images in Adobe Illustrator. One as transparent, the other as white. The transparent one showed up with a big blue question mark. Running it, worked fine however. Something to do with IB and transparent PNGs

Servant answered 24/11, 2012 at 20:36 Comment(0)
B
2

just for the record (because nothing worked for me):

We only had retina-graphics in our projects. After update to XCode 5 all images had a white question mark in it (only in the Interface Builder, not in Simulator). We switched the image source to non-retina, which solved the case!

enter image description here

Using btn-category-6.jpg solved the issue!

Bluenose answered 22/10, 2013 at 10:37 Comment(0)
Q
2

For me it was because the images had a ".png" in attributes inspector. Removing it fixed the issue

Quirinal answered 16/6, 2014 at 14:15 Comment(0)
I
1

Just an FYI: I had a similar problem. At some point the images were corrupted and they were all Transparent PNGs!

I replaced the files and now they are showing again. The image corruption may have happened when I copied the files via Windows Explorer in Oracle's Virtual Box running Windows XP.

Inocenciainoculable answered 22/5, 2011 at 19:28 Comment(0)
C
1

In my case when I have created new project in Xcode 6 I can not show the images in the Simulator and as well as in device. I have imported all the images in the image assets making a folder within that.Now I have imported all the images, all are working fine now. All images are now showing now.

Follow these steps:

STEP 1:

Step 1:

STEP 2:

Step 2

STEP 3:

Step 3

and then Import images which you need. Reference Link: StackOverflow link

Clotho answered 25/11, 2014 at 13:13 Comment(0)
F
1

For me the problem was, I could see the new added image files on Show the media library but not in the dropdown for my button Image

For me the solution was, typing the name manually. When I started typing the image names in the text box, it autocompleted it and that's it. |

PS: I also implemented the selected solution before doing so

enter image description here

Fryer answered 22/8, 2018 at 12:21 Comment(0)
P
0

I had the same symptoms, but I just moved the project folder to the desktop, re-ran the project in IB from there and it worked! Then work it back into the same parent folder again, with a different name...strange.

Painful answered 12/5, 2010 at 15:33 Comment(0)
H
0

I had this problem several times. And copying the project directory to the desktop, renaming the original folder, opening the project from the new location and moving it to the original directory again helped every time. All those "Load all header files" solutions sometimes work and sometimes don´t

Hollinger answered 28/2, 2011 at 19:13 Comment(0)
P
0

This happened when I moved the images to xcassets. I solved it by removing png and jpg extensions on inspector.

Poulter answered 29/5, 2014 at 11:35 Comment(0)
B
0

The .png was missing from the end of my image name in attributes inspector

After cleaning, re-importing and checking the assets where mapped correctly, nothing worked, though I found my image (which is a png) showed up once I entered .png at the end of the image name in the attributes panel.

enter image description here

Buckling answered 21/5, 2015 at 11:20 Comment(0)
B
0

Make sure you're referencing an image asset that actually exists. I had added my files to the Xcode Asset Catalog (.xcassets) as usual, but forgot to rename from the default name of "Image" to the name I was using in the storyboard.

Betthel answered 21/10, 2015 at 14:22 Comment(0)
K
0

If you have all of the 1x, 2x, and 3x images set, cleaned and built the project and it still doesn't show up correctly, exit Xcode and force quit, then open Xcode again. Just a simple Xcode restart worked for me.

Kelton answered 4/5, 2017 at 8:46 Comment(0)
G
0

Make sure you have an asset matching the image scale that matches the screen size you are viewing in your Interface Builder file in Xcode. There are @1x, @2x, and @3x spots for image assets if you're using the asset catalog in Xcode, or, if you're not using it, then you should have different assets differentiated by their file name (e.g. "image.png, [email protected], [email protected]).

You may not have multiple asset sizes and just have provided one asset for say 1x or 3x and you may be viewing the screen in Interface Builder for a device type that uses a different asset size and thus the UIImageView's image won't render in Xcode. For example, I was viewing the interface for an iPhone 7, which uses 2x, but the asset only had a 3x version. When I added a 2x version it immediately showed up in the Interface Builder in Xcode.

Note that even if it doesn't render in Xcode, it may still render properly at runtime. Still, it's good practice to provide assets at resolutions that will be appropriate for each device model.

Grenadines answered 19/5, 2017 at 21:1 Comment(0)
S
0

I've ran across this problem a few times - sometimes (I'm not too sure why...), Xcode seems to forget the link between a UIImageView and the image in your folder.

It may then be as simple as going to the attributes inspector for that image view, and if the image box says 'Unknown image', re-selecting the correct image!

UIImageView attributes inspector

Scrounge answered 6/9, 2017 at 9:21 Comment(0)
R
0

If none of these answers work, one possible reason could be: If you are using a UIButton and displaying an image in it, make sure that button does not have a title. It will show an ellipse (...) because the button caption is being truncated.

Rici answered 15/8, 2018 at 23:29 Comment(0)
W
0

For me, I just need to click on my assets and view the images there briefly. Then I return to the storyboard and the images are populated.

Whorish answered 27/3, 2019 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.