This one has me confounded, so I'll try to go through the chronology so someone smart than I am can show me where I'm going wrong.
Everything was working perfectly on my app, both on the device and on the simulator. I have an image file, myimage.png, that is located in the directory where my project is and has been added to the project. It shows up in XCode and everything.
I build, run, and things work as planned.
Then I decided to get clever in photoshop and spruce up my image with a bit more color. In the finder, I deleted myimage.png from the directory where my project is located. Then I saved the new image as myimage.png in that very same directory. Back in XCode, the file shows up in the project and looks just as nice as planned.
I build, run, and no image shows up. WTF??!?
Here are my two questions, in order of importance:
How do I fix this so that my image shows up again?
What have a done wrong in this process?
Thanks!
EDIT: Here is the code where I am calling the image. In myViewController.m:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
// SOME CODE THAT DOES OTHER THINGS UNRELATED TO imageView
[imageView setImage:[UIImage imageNamed:#"myimage.png"]];
// MORE CODE THAT DOES OTHER THINGS UNRELATED TO imageView
}
ANOTHER EDIT: Not one single character of my code changed between the app working and not working. I appreciate all of the suggestions since I clearly cannot figure this one out on my own, but the problem is most likely not with the code.
easy: in xCode delete the file reference and the files themselves and then import it again...
mhm... when you changed your image was xCode opened? it may have seen somehow it's been deleted and lost the link... if you change it xCode could "choose" to NOT include it in the target mainBundle when you build your project... in xCode select the file and see if the checkMark on target is selected:
if not it won't be included in you app (and this answers to your n:1 question too)...
maybe a better way to add a resource files which could be probably be modified by other programs in future while yourProject could be opened (i do it with an html site to be included, jpg and gif too) is to put them in a subFolder of your project and then add all that folder to your xCode project AND in the dialog window choose:
"create folder references..."
that will create a blue folder in xCode and all its contents will refresh automatically if you change, add, delete files or subfolder inside it...
BUT remember that the subFolders will exist in the same tree-order in your app mainBundle, so if you need to load a .png you need to specify where to find it.
PS
check also that the file name is exactly the same of the old file, including UpperCase chars
("a" != "A")
I think that happens because Xcode doesn't know that the file has changed. Always add/remove files in the project navigator.
It should work if you clean your project and build again.
You'll need to do a Build -> Clean. And the rebuild.
Related
For some reason, XCode is acting up really oddly. I have been testing XCode's ability to load images with the -hd suffix, and realized that Xcode will load a file "welcomeBackground.jpg" regardless of whether it is actually in my project folder.
See, this code below will not crash when compiled. And this is the first screen that is displayed when the app loads. I deleted the file "welcomeBackground.jpg" from my project folder, and XCode still loads the file as if it were there.
This is really freaking me out. Please help?
I am 200% sure I deleted the file from my project folder even and yet Xcode does not crash on line 35.
EDIT: To repeat, things I have tried/checked
- Cleaned project
- Deleted Derived Data
- Checked for hidden files in project folder
- Deleted app from iPhone and re-run from XCode
- Deleted the files from my project folder
- Loaded another image "sadhieia.png" and crashed Xcode
because Xcode couldn't find the file (as it does not
exist), and then tried "welcomeBackground.jpg" again
and Xcode somehow finds it.
And yet, the background still loads...
In Cocos2d, if the specified image is not in your folder, it'll not crash. Instead, it'll return nil to your CCSPrite *background.I suggest you Don't use Camelcase for images. Use lowercases or underscores. Try deleting Derived Data. See this for how to delete derived data.
Scroll the project navigator down to the bottom, to "Products," then click the disclosure arrow to show your application.
Right-click the application and choose "Show in Finder" from the contextual menu that appears. A Finder window is displayed containing your application.
Command-click the title of that window; another contextual menu appears. From that, choose the folder "Derived Data." The Finder then displays a window for that folder.
In this window, you'll see a folder whose name is that of your application, followed by a long string of letters. Trash it. If you see multiple folders bearing your application's name, trash them as well.
Rebuild your project. That should take care of the issue.
This might be a slash and burn approach, but it's solved a lot of quirky project-related issues I've experienced in Xcode after attempting to clean.
Clean your project; your image file is still cached in the build folder.
I am using Xcode 4.3.3, I already tried to build my app before and it run. But now I arranged my files inside my project's folder, grouped them by 'button' , 'icon' , 'background'... I also copied some resources/images in other folder put them in order but now I'm in trouble.
Im trying to build my app again in Xcode, I found a CopyPNG Error:
Can't find /Users/vella/Desktop/Sample/res/2.png
Command /Users/vella/Desktop/installer/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/PrivatePlugIns/iPhoneOS Build System Support.xcplugin/Contents/Resources/copypng failed with exit code 1
Now, I don't know if I missed some png files. I also read some answers like I should save PNG files as NOT INTERLACED or there is a PNG file that is corrupted. How will I know what PNG file is missing or corrupted?
Check wheather you added 2.png into your project folder.while adding images into your project,click the checkbox "Copy items into destination group folder".If your png file is corrupted, it will be in red colour in your project.
You have to save your PNG files as NOT INTERLACED. For example, bu using Photoshop, go to menu File->Save For Web and Devices. Unchecked the box of 'Interlaced' and save the file. Usually interlaced box is unchecked already. Hope that helps
Clean up the png file in your project and re-import it:
Delete (backup) that file in project navigator. Just delete and move file to trash can.
Go to project Build Phases:
i. Select the root project
ii. Select TARGETS
iii. Select Build Phases tag
iv. Expand Copy Bundle Resources list
If you see the file you just deleted still exists (maybe in red), delete it
Re-import the file again
This worked for me.
Yep, Add it again and this time dont arrange or rearrange any stuff in your resources folder.
Also give specific naming to the images so that its easy for you to remember and implement them later in ur project.
I just had the same problem. I always do the same thing to add images to my projects but I never had a problem like this before.
I found in the error message that, the image path that Xcode was trying to find the image was wrong. The path that Xcode is searching was like " ...../My Project Folder/images/favourites.png" but the correct path is like "...../My Project Folder/myProjectName/images/favourites.png". To solve this, I create a folder with path " ...../My Project Folder/images", then I backed up my images and deleted all of them from project window and selected "move to trash". I copied and pasted the images from my backup folder to this new folder. Then I drag-dropped them to "Supporting Files" and select "Copy items into destination group's folder (if needed)". Finally I cleaned the project and run it. It worked for me. Good luck.
I've been trying to update an image that is packaged with my app, but the app refuses to load the new file.
I originally had a png called "board.png". I then created a new file which is a higher resolution copy of the original. I deleted "board.png" from the Resources group in XCode and added the new image under the same name. When I run the app, the old, smaller image is still used.
Then, I cleaned the build and tried again. Still doesn't work. Next, I renamed the new image to "BigBoard.png" and tried loading that filename thusly:
UIImageView* board = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"BigBoard.png"]];
but the image does not load at all even though it is in the Resources folder. Does anyone else have any experience with this? Any help would be greatly appreciated.
Thanks!
I had the same problem twice now.
The first time I had just forgotten to check the 'Copy items into destination group's folder' option when I added the new image so the image want actually in the folder when I went to build.
The second time I needed to clean all targets (Build -> Clean All Targets) before I built again. This gets rid of all the precompiled stuff and forces xcode to completely recompile the project. When I did this the build results showed an extra action CopyPNGFile "path/to/image/image.png" so I think it was avoiding adding new image because it saw a precompiled version of it there already.
See if either of those fixes it.
I actually found the solution to this problem a little while ago. Since I converted my iPhone project into an iPad project, the new files I add to the project were not added automatically to the iPad target and would not be present in the iPad executable. To solve this problem, I had to manually add the files to the iPad target by right clicking the file -> Get Info -> Targets -> Check iPad target.
The recent XCode update also fixes this problem so you no longer have to manually add the targets.
My problem is something that should be so simple it is mind boggling. When I change the look (in PhotoShop) of an image file that is being stored in my app bundle. My method for replacing the old image in the bundle with the new one is this:
1) remove the old image from the app bundle (choosing to also move to trash)
2) drag the new image into my file hierarchy in xcode (choosing to copy to app directory)
when I do this, the app cannot find the image no matter what I do. The new images have the same name as the old images but none of the image loading methods (imageNamed, imageWithContentsOfFile, nibs) work. (Although I believe nibs also load with imageNamed, i'm not sure).
Is there something that I am missing here? I feel like it should be a relatively simple process but I am having all kinds of trouble. I also make sure to delete the app off of the target device and clean all targets before rebuilding and running after changing the image files just in case.
Any help would be appreciated.
Thanks
Your problem is probably that the image is not copied to the target. In xcode groups & file pane, fine the node for targets, expand your app target and you'll see Copy Bundle resources expand it and you'll see all the files copied to the default resource bundle when you deploy your app to the sim/device. Only the resources found there will be available to your app. If you don't see your image there you can just drag it there and everything will work.
Now, in order to understand why this might happened we need to look at the different options for adding files to xcode.
When you're adding a file to xcode you are presented with a dialog that includes a few interesting and sometimes overlooked option.
The first - Should the file be copied to the project folder, or should it just point to the file original location. The safest way will be to always copy the files to the project's path. However for images (such in your case) I do it differently. I maintain a separate graphics folder for every app, I save images there (both sources, and final png). When I add an image I do not copy it to the project folder, rather xcode just points to its location. That way I can just edit the image in photoshop, do a rebuild, and the updated image will show up on the phone. Whats important to understand that the directory structure of files you include in the project have almost no meaning, files that appear in the Copy Bundle Resources for the target will always be copied to a single (and flat) bundle/"directory" on the phone. The only exception for this is if you actually add directories to xcode (Personally I recommend against it).
The second option when adding files, is to which targets to add the file. This is the list with checkboxes on the bottom, if when you added the image, your app target wasn't checked the file won't be included in the target Copy bundle resource, and won't be available for the phone.
A few caveats - When using references to files in other location, that location is relative to the project's path, so it's a good idea to keep all the files in directories below the project's root directory. That way you can still copy the entire project to a different location and it will still work.
Great advice above: I thought I would add more for future searches on this topic:
I was adding and removing images to the project just like above:
Remove the old image from the app bundle (choosing to also move to trash).
Drag the new image into my file hierarchy in xcode (choosing to copy to app directory).
However when I tried to drag the new image with the same name to my file hierarchy in xcode I was getting an error that this was not allowed.
Turns out when I was removing the old image Xcode was removing it from the project file hierarchy but the actual file wasnt being removed from the project's root directory.
I solved my problem by removing the image from the project's root directory and added the image again!
Do you put your images in a custom sub-folder? If you just drag in images into the Xcode project tree, if you copy them, the images will be copied to the root of the project directory, instead of the "Images" or other folder you might have set up.
Note that you can right-click on the image in your bundle, select "Get Info..." and reset its location, if it has been moved or copied to a folder you didn't expect.
I'm having some weird issues with Xcode, and this is pretty much impossible to find answers by simply googling around.
I have a few icon image files (just PNGs) in my Xcode project, and when I modify some of them in Photoshop, they don't get updated when I do another build in Xcode. In order to fix this I have to re-add the file again to the project, and then remove the old version of the file that is already in there in Xcode.
What am I doing wrong here? I'm updating/replacing the image file that is stored in my project's directory directly from Photoshop, so I assumed that it would just get reloaded and the new version would show up.
UPDATE: Looks like what happened was that when I first imported the image files into my project, they got added to my "Classes/" sub-directory. So when I was updating them, it was just adding them to the root of my project.
I had the exact same problem.
The following fixed it for me:
In Xcode, go to Project --> Clean
This will purge the old images from xcode cache and will show your new image
That's pretty weird. I'd suggest two things:
Check that you're not saving your
photoshop files into the wrong
directory. I know this seems
straightforward but its worth a
check. Make sure you're not saving
them into the build/ directory or
anything like that.
Before running again in the simulator, try cleaning all build targets first to ensure that your project actually builds again before launching the simulator.