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

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!

Related

xcode view size smaller than iphone

That never happened before iOS 6.
Now, I create an "auto layout", and I realized that the size was different in xcode, because the image was large but was correct in photoshop. When creating the app in the simulator, I have this:
I kept finding weird. So checked the size of the iPhone 5 and moved, as I always did, then looked like this:
When creating the app in the simulator, looked like this:
I wonder what happened with Xcode? Someone went through this already?
Thank you
It looks like you are working with an XIB that was identified as for iPad. In the Attribute Inspector, what options are you given under size? An iPad XIB has these options in Attribute Inspector - Size:
If that is what you see, you may have to create a new XIB, and be sure to choose Device Family - iPhone.

iOS App won't use 4 inch size even with default-568h#2x image

Everything I read (including on Stack) keeps saying that in order to have an app use the entire 4" iPhone screen you simply have to add a default-568h#2x.png image with a resolution of 1136 x 640.
I've added this image and when I run on a 4" iPhone simulator everything (including the launch image) renders windowed with the black bars at the top and bottom. I've tried deleting and re-adding the image, made sure it shows up as the 4" launch image in the Target summary tab, and adjusted all of the simulated metrics sizes in my storyboard to be Retina 4 full screen. Even with all of this, I'm still getting the old 3.5" window.
Is there something I'm missing or doing wrong?
You spelled Default-568h#2x.png wrong. Remember that iOS is a case sensitive file system, so the capital "D" matters. (I had a very similar problem -- which is what led me to this question -- because I was missing the "h" )
I'm not certain on what the issue is but a couple more checks you could do would be to make sure you have built the latest version of your project before simulation. The simulator may be launching a previous build that did not have the 4# images
Maybe try temporarily removing your smaller resolution images to see if that makes a difference.
Also make sure when the simulator is open that you have the correct hardware configuration in the hardware tab

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"];

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

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"]

ObjC - Hiding the separator lines of a UITableView on iPhone

I try to do this with following line:
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
and it works! on the simulator.. strangely when I run the app on the iPhone (3Gs) they show up again.
Any ideas why this could be happening?
(Also labels and images of my custom cells are displayed on wrong positions, maybe its the same problem)
There is absolutely no difference between the simulator and the device code (it's the same code that gets compiled).
It seems it was an Apple bug. I updated to iOS 4.0.1 (with XCode+SDK update as well of course) and now everything works just fine.