Images in iPhone app appear in Simulator, but not when compiled to device - iphone

I am learning iPhone development, and have built a simple app that has an image that changes to another image when you tap it.
If i build it to the simulator, it works fine, but if i build it to the device the images dont appear. i feel like they aren't being copied across. I have checked they have been named correctly and i have made sure i imported them to 'resources'
I dont think it is a problem with the code because i added a thing to also make text appear when the image is tapped, and this works, so a button is still there doing something, it just doesn't have an image on it.
-(IBAction)changeImage:(id)sender {
[fortuneCookieButton setImage:[UIImage imageNamed:#"Image2.jpg"] forState:UIControlStateNormal];
label.hidden = NO;
}
-(IBAction)restoreImage:(id)sender {
[fortuneCookieButton setImage:[UIImage imageNamed:#"Image1.jpg"] forState:UIControlStateNormal];
label.hidden = YES;
}

Does the case (upper/lower) of all your file names match exactly for all letters? Source code & project & Mac?

just to share with you, I had this same problem and I found out the solution: I was using lower case in the file name and upper case in code. The thing is on Simulator there was no problem because Mac file system is case-insensitive but in the iPad it didn't work because iOS file system is case sensitive. ;-)

I had this problem. Bizarrely the image had been working in the past, then just stopped appearing on the device one day.
It was a PNG.
I opened it in GIMP and saved it again. Then it went back to working again. No idea why.
Crazy.

Is it the case with only PNG images or also for JPG & other format you're having same issue. If it's only for PNG image, then it might be possible they're not being compressed. Try the following way.
Select your project target & go into its info. Here go into the build tab. In the configuration select "All Configurations" from Configuration section. Now, write "COMPRESS_PNG_FILES' in the search bar. And see the status of the check-box. IF it's unchecked, then make it checked & it will work. But if it's already checked, then there should be other reason in your project.
In the later case, I would request you to create a new dummy project & check by adding 2-3 images whether it's coming or not.

Clear caches delete the previous build and try again.

I also had same problem, and it was caused by a different reason: my project has image files with the same name! Since my app has many images, I inadvertently included images with the same name. Simulator is more tolerant and show the images just fine; however, when built on device, neither of the images of the same name were copied to the build directory. Obviously xcode is more picky for device: since all images go to the same directory, the file names must be different. When there are files with the same name, xcode refuses to copy any of them since it doesn't know which one to pick.

I have the same problem. In my case, the issues is to do with the UILabel above the UIImageView that shows the image. When I change the type of UILabel to AttributedText (In Property Inspector), my real devices cannot load the image. When I change it back to Plain, it works now. I use XCode 6.2.

on top of all suggestions - it wasn't work for me until I restarted the device

Related

WatchKit Extension[4608:145616] Unable to find image named "hello" on Watch

Problem:
Trying to set the WKInterfaceLabel text using xCode 6.2 but it returns this error:
WatchKit Extension[4608:145616] Unable to find image named "hello" on Watch
Code:
#IBOutlet var lblPassword: WKInterfaceLabel!
lblPassword.setText("hello")
Cleaning the project doesn't seem to fix the issue for me. But if you click on the image file, you'll see "Target Membership" options on the right pane. Select all of them, Clean the build and try again.
I got the same error although I am pretty sure these image files exist.
I just terminated Xcode, relaunched it, cleaned the project (command + K) and built it. It started to work again.
I do this routine whenever I face a new problem. It solves most of the problems as you might know. Sorry if you have done it already.
I supposed that you adding image to asset catalog in WatchKit Extension. This is wrong.You should add that image to asset catalog in WatchKit App. Sorry i can't add image here.
Try as I might, my images were not loaded up to the watch until I did it directly by 'caching' as follows in my InterfaceController in the WatchKit Extension:
[[WKInterfaceDevice currentDevice] addCachedImage:[UIImage imageNamed:#"carrota.png"] name:#"carrot"];
[self.portfiolioImage setImageNamed:#"carrot"];
For me, it looks like you have added "hello" as an image name somewhere in the storyboard.
Use XCode's Find dialog to look for "hello". It will show use as an image name, too.
Screen Shot 1
Ok So the keything to note here is that "you do not want to drag and drop the images into the AssetCatalog"......the only way this worked for me was to manually right click on the catalog (as shown in screen shot 1 and "Add Files"....look for the image you want to add on your local/external drive (Making Sure that only the "WatchKit App" Checkmark is selected in the Add to Targets Section" as shown in Screen Shot 2) and add the images!!
Screen Shot 2
i've had the exact same problem. solution: i've exedently connected the group parenting the WKInterfaceLabel. Try setting YOURSUPPOSEDLABLE.setTextColor(.brown), if the Background of it changes, you have connected the group.
So in my case I had copied and pasted a prior row and assigned a diff class.
That duplicated row's group still had an IBOutlet connection to the prior class that I did not catch.
Once I removed that connection this stupid issue resolved itself and I was able to successfully call .setText()

Resetting iPhone Application

I have an application that is currently named "xxxx". The app runs and works perfectly without any problems. However, I have reached a stumbling point. When I try to load the application onto my iPhone, the pictures on my picker view seemed to have disappeared for some strange reason. I've done multiple hours of debugging and everything checks out normal. I then decided I wanted to change the product name from "xxxx" to "xxxx Redo". As soon as I did that, the application loaded perfectly normal (with the pictures in the Picker View as it should be).
In conclusion, it comes to find out that there is no actual bug in the programming aspect of it. However, my question comes up as to why does it not load the correct way with the original product name but then loads the right way when the product name is changed?
The second part of my question is if anyone knows of a way to fix the original application so that way it displays correctly again with the original name?
I have tried the following:
Cleaning the app
Trashing the .app file and rebuilding
Deleting the app on the iPhone and rebuilding.
These things sometimes just happen, you can try the following extra steps:
clean build folder in XCode (press alt while clicking Product menu)
reboot the phone (poweroff/poweron)
I have seen cases where it made a difference.

Deleted UILabel in Interface Builder still shows up

I am having a bug that has got me stumped. I created a label a short while ago that was just a placeholder to be replaced in the future. Finally, I get to replacing it with a button, so I delete the UILabel and put a UIButton in its place (keep in mind this is all in Interface Builder). When I run the program in the simulator, the new button isn't there and instead there is the old label which has been deleted. I have searched my whole program and I have no reference to this label, it is completely out of my program, yet it still appears in IB and my new button does not. I have tried Cleaning the program and quitting Xcode several times to no avail. If anybody knows of or has faced a similar problem I would love to hear your solution.
Thanks,
Kyle
It seems in your case NIBs are cached in Simulator, delete your app from inside Simulator and rebuild/reinstall then it shall be fine.
With xcode 3 I would have guessed that you did not save the xib file within Interface Buidler.
Still in xcode 4 I sometimes get the impression that not all changes come to effect for whatever reason. As if one or two source files do not get compiled at all.
Then I close xcode, save everything and start over again.

not able to change image in UIImageView control

This seems to me as a bug because I have changed images with:
someImage.image = [UIImage imageNamed:#"anotherImage.png"];
and I have never had a problem. so let me show you what I have:
I have placed an UIImageView:
note that imgObjetivos is conected to this UIImageView.
I have a method that get's called when clicking the following button:
and the method contains:
as you can see I just want to change the current image with:
so when I run the application in the simulator everything looks great:
and when I press the button the image changes successfully:
Now why is it that when I run the application on my iPad the image does not change!? when I press the button the image disappears instead of getting a new image like in the simulator. I just learned objective-c and I am starting to dislike it. What am I doing wrong?
EDIT
I found a solution I changed the name of the image and now it works:
but this makes no sense. Which names works and which ones do not? I also have make sure that I don't have two images with the same name and that is not the case. when I have a few letters after the '_' underscore it does not work. This is really strange. I am starting to dislike objective-c :(
I've had the same problem before. The problem is that the image that you're using to replace the previous image is corrupted or say is not in it's original format.
In my case, I downloaded images in the web which was .jpg format and renamed it as .png format which actually made it .png. so in short term, ipad does not support the functionality for converting image format by just renaming the extension. you have to have a proper converter or something.
I would go with removing the image file from the project, clean the project and add the file back.
I had to rename the image name to something else I don't understand why... I thought that the problem was because I previously deleted that image that contained the same name but that is not the case because I imported the image with a similar name to the solution and I had the same problem. for example the original name of the image was objetivosFoto_h.png and when I renamed to objetivosFoto_ho.png it still did not work but when I renamed to objetivosFoto_horizontal.png it worked.

iPhone simulator shows app's images but iPhone does not

I have create an application on iphone using objective-c.In this application i am just displaying different players images stored in one folder, which will be run perfectly on simulator. But when I deploy it on iphone it is not showing the images of the player.
for that the code is:
UIImageView *imageplayer = [[UIImageView alloc]initWithFrame: CGRectMake(imgx, imgy+45,135,150)];
imageplayer.image = [UIImage imageNamed:playerpng];
if(imageplayer.image == nil)
[imageplayer setImage:[UIImage imageNamed:playerjpg]];
if(imageplayer.image == nil)
[imageplayer setImage:[UIImage imageNamed:#"noimage.png"]];
[self.view addSubView:imageplayer];
Plz solve this query.
Thanks in advance
Sometimes xCode doesent update correctly the bundle, try cleaning and building again.
I am currently experiencing this problem as well. I was able to correct it after a bit of debugging and reviewing the build file.
When I do an ls -l, I noticed that some of my png files have a # symbol beside the permissions. When I followed that up with a ls -l#, it showed that the files with an '#' had an attribute set 'com.apple.quarantine'. This attribute is given to a file (often from a zip, jar, or other executable) that is downloaded from the net. You can get rid of this attribute by performing:
xattr -d com.apple.quarantine *.png
Then, select the images in XCode, and check that the checkbox under the target is checked. In my case, it was not, so the images weren't being included in the bundle.
I had the same problem, solved by using all lowercase for the file name in code - image.jpg, but it does not seem to make any difference what case the actual file name is, e.g. Image.jpg
check name of image file. It must be "noimage.png"
not Noimage.png or noimage.PNG
Just to clarify, does the "noimage.png" display, or is the program loading a player image but failing to display it? Or is nothing loading.
These should easily be determined in debug mode.
A few additional things to check...
1) Just for testing, start out with PNG versions of the player files. This is the primary format on the iPhone and might eliminate a file format issue or other anomaly that the simulator is not sensitive to.
2) With regard to fixing in an image editor, specifically make sure that the image is set to a DPI of 72 pixels/inch. The iPhone and particularly Interface Builder are very sensitive to this being correct and will sometimes not display or will display a very blurred version of the image if incorrect.
3) Make sure the image(s) haven't been added multiple times (from different directories and/or to different group folders). We encountered a situation where we had inadvertently imported the same images at two different layers within the project hierarchy and this can cause unexpected behavior within the iPhone (selecting randomly or failing to select).
4) Make sure the Get Info -> Targets has your particular target checked. The simulator may still see the image but it will not get deployed to the iPhone.
5) Make sure you can view the image within XCode and that it looks correct.
Barney
This happens to me sometimes. I once spent half a night trying to figure out what was wrong. In this end, this is what worked: open the image with an image editor and save it again. That's all. I'm using the free Acorn image editor to do this. Haven't tried it with Photoshop. (After all, it seems that Photoshop might be responsible for introducing the error in the first place, although that's far from sure.)
I don't know what causes the problem. I usually get it when I use png files that have been sent to me. Could be a simple file permissions problem, or some more subtle problem with the image format. I would be very interested in hearing the opinion of better-informed people.
In any case, if all else fails just try this: open the image with Acorn, save over the original file. Works for me.
Make sure the image files are added to your XCode project.
After some investigation, Michael's comment seems to have a solved it for me. I had all lower case as the file name but was following variable convention and had the png file with an upper case for the second part of the file name. Here my file was putback.png but was referenced in my code as putBack.png
UIImage *putBackImage = [UIImage imageNamed:#"putBack.png"]; //wrong
UIImage *putBackImage = [UIImage imageNamed:#"putback.png"]; //correct
Select correct target while adding image files to your project. Following are steps to make it further clear
Select Add Files to "YourProjectName"
In opening window there is an "Add to targets" option at bottom that shows all available targets
Check target or multiple targets in which you want to add images
Press "Add" button and you are ready to go