Why are images shown only on simulator but not on device (iPad) - objective-c

My array has the value:
imageArray = [[NSArray alloc]initWithObjects:#"image1.png",#"image2.png",#"image3.png",#"image4.png",#"image5.png",#"image6.png",#"image7.png",#"image8.png",#"image9.png",#"image10.png",#"image1.png",#"London.png",#"image2.png",#"image3.png",#"image4.png",#"image5.png",#"image6.png",#"image7.png",#"image8.png",#"image9.png",#"image10.png",nil];
I want to show these images in a scrollview. All the images appear except #"London.png", which is appearing as blank. How do I fix this?

I've come across the same problem when i wasn't carefull about capital letters in file names. For example file Image.png (if called as #"image.png" from code) was normally shown in simulator but not on device. So make sure your names match exactly. Is your file London.png actually london.png?
And it has to be added to the project and to the target.

...if error persists try to save again your png files.
sometimes png files are not saved in the right format, and even if you can see them on a mac (and in simulator) they are not readable in IOS devices

1 - Open your [myApp].app product folder and check your images are really embedded.
2 - Check that your image is really a png and not a simply renamed jpeg.

Besides the case, images are even displayed without the extension on the simulator.
While [UIImage imageNamed:#"test"] does work on the simulator, it will not on an actual device, it has to be [UIImage imageNamed:#"test.png"]

Related

OS X Screensaver: Retina Thumbnail Image

I'm developing a screensaver for OS X using Xcode's screensaver template. By inspecting the package contents of system screensavers, I've found that the thumbnails used in the System Preferences list of screensavers are derived from two files in the screensaver bundle:
thumbnail.png (90x58)
thumbnail#2x.png (180x116)
I have created two images of these sizes and placed them in my screensaver bundle. However, the System Preferences panel on my retina screen appears to load the non-retina asset. Here is a screenshot of the System Preferences panel next to a QuickLook preview of the thumbnail#2x.png image:
I'm out of ideas. Anyone know what could be causing this and how I can stop it? Things I have tried:
Using tiffs instead of PNGs. -- Same result.
Naming the retina-sized asset thumbnail.png -- Same result.
Turned off "combine high-resolution artwork" in Xcode's build configuration. -- Same result.
Deleting the thumbnail assets altogether. Interestingly, the System Preferences panel does not go back to drawing a default thumbnail icon. Instead, it draws an empty white rectangle. This led me to believe there might be caching going on, so I spent some time trying to find where that would be. Cleared preferences, etc.
Oddities
If you inspect a system screensaver's package bundle, you'll find that the two thumbnail files don't report dimensions in the Finder. And if you open them with Sketch, they BOTH appear as 90x58 to that app. (Although Photoshop shows the #2x asset as 180x116). The thumbnails from the system screensavers have the gloss effect already applied, whereas my thumbnail gets that effect automatically even though the image asset does not contain it.
I'm starting to think there's something fishy about the way the panel loads/draws these images. Maybe somebody knows something I don't?

Are there specific settings I need to use when preparing images for use with custom UITabBarItem's?

I'm using free images off of iconfinder and they work fine. However I couldn't find a specific image so had to find the image elsewhere.
Anyway the image was an incorrect size so I resized it in photoshop.
I added the image to the images.xcassets folder and used the image for the uibarbuttonitem.
The image has come out as a grey square box.
Highlighting works but all I see is a box.
Am I missing something here?
Would appreciate some help thanks.
Make sure the image is a PNG. What is the size of the image you are using?
Apple's iOS HIG
I had to change a setting in photoshop. When saving the photo I had to make sure interlanced was chosen.

Strange issues with file name and Xcode sim vs. ios device

I just spent a day trying to figure out why some simple code was not loading images from the resources folder. Just for kicks I went into the finder and renamed one of the files to exactly the same name and it loaded. Then I did the others - simply renaming them to the same name. I looked and there weren't any strange characters or whitespace before or after the file name. So now they all load fine into an array in the simulator. But now on my device, they aren't loaded into the array, returning "nil" and are throwing exceptions. I know that ios devices are case sensitive where the sim is not but I checked this and the naming is all fine. The only thing I can think of is that my images are named for retina (#2x~iphone) and my device is not. But I have images named the same way, for retina, and those load fine.
I am using imageWithContentsOfFile to load the images and also getting a memory warning after it tries to load the images. I am not sure if the memory warning is related.
I think the problem might be in your file naming. Remember that you should include both retina and non-retina graphics in your app. Seeing as you added "~iphone" I'm assuming this is a universal application so your images should be named as follows:
myImage~iphone.png
myImage#2x~iphone.png
myImage~ipad.png
myImage#2x~ipad.png
Then in your code you only reference the "myImage" part of the file name so iOS can sort the rest out for you.
For example:
UIImage *image = [UIImage imageNamed:#"myImage"];

Can't find image while running on device, but can find it while running on simulator

I'm trying to load an UIImageView with an UIImage using [UIImage imageNamed:name]. The simulator works perfectly loading the image, but running the same code on an iPad terminates with an exception (because the UIImage ends up being nil). Why is this happening?
I added the images from XCode to 'Supporting Files/Images'.
Weird thing is that some files I added are being found ok, but these other images are not. The only difference between them is that I renamed the ones I cannot find from within XCode. I even tried removing and adding them back again, but no dice.
Case is not the issue, I already checked it.
This is on XCode 4.2 and iOS 5.
Any clues?
Thanks
Image names are case-sensitive on the device, but not on the simulator.
If your case is correct, reset the simulator.
http://www.jameskelso.com/post/9627437152/images-show-in-the-ios-simulator-but-not-on-a-device
Make sure that the images exist in the "Copy Bundle Resources" section of your target's Build Phases. Whatever you do, try cleaning your build folder first (option+shift+cmd+k). Good luck!

Automatic inclusion of #2x images (retina support)

Can any one tell me code of auto including #2x images if device is switched to iphone 4.
I have searched very far on it, but nothing fruitful is found yet.
I have already included #2x images in my resource file. I want code to write so that images resize and reposition them selves when application is running on iphone 4.
What do you mean by "auto-including" ?
If you have fooBar.png and fooBar#2x.png in your project resource, then when you do :
UIImage * fooBarImg = [UIImage imageNamed:#"fooBar.png"];
It will automatically load fooBar.png if your screen scale is 1.0 (iPhone3G/3GS) or fooBar#2x.png if your screen scale is 2.0 (retina, iPhone 4).
cf UIImage#imageNamed
Just include the #2x with the normal image in your project, the os will get the #2x if needed.
When you refer to an image always refer to the non-#2x image and iOS will get the #2x image on iphone 4 (or ipod) if you take it in your project and add to the target of course.