XCode buggily loading images that aren't in my project folder - iphone

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.

Related

How to change location of iPhone app icon?

Okay, I am a noob. It must be simple but I stuck here.
I do rigth-click and choose 'select file'.
After I choose the file the dialogue appears:
I want to keep my icons not in the root directory. But I can't figure out how to do this. I tried different ways, even create project from scratch...
Please help.
When you bring image assets into Xcode they will all be in your application bundle's root directory at run time.
It appears that you've added a file named "icon#2x.png" to your project at one time already. Go to the project's summary page in Xcode click Build Phases and then expand the section titled Copy Bundle Resources. There you'll find the reference to the resources that will be copied to your bundle at run time.
More on bundle structures here:
https://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html
Anyway, the way I've done this in the past is to:
Remove the existing image duplicate from Xcode and from the folder structure in Finder.
Add a new folder in Finder call it "/AppIcons" (or whatever).
Copy all the app icons to that folder in Finder.
Drag the "/AppIcon" folder into your XCode project. I typically put images in an "/Images" subdirectory in the Xcode project. Again you can put it wherever you'd like.
In Xcode on the project summary panel, add your app icons from the folder "/AppIcons" by dragging / dropping or by right clicking and adding them as separate files.
Alternatively in the past when I've had problems with this sometimes Xcode will copy the app icons to the root project directory. If that happens, I make sure that I have the "/AppIcons" folder structure on disc (in Finder) and in my Xcode project. I add the app icons to the project, then move them to /AppIcons in Finder, and re-reference them all over again.
Your Copy Bundle Resources should then have the proper file reference. Note that my apps icons go in "/Images/AppIcons"
Good luck!
I would add the image files to your project with the name icon#2x.png. To do this right click where you want to add the files in xcode and click add file/s. Then search for your image and add them using the dialogue that pops up. - there is a check box so that you can either copy them to the projects destination folder which will copy them into you project folder or leave it unchecked (inadvisable) which would reference it's current location on your HDD. Make sure the file doesn't already exist in the project before doing this!
EDIT:
Sorry I forgot to mention then drag and drop the file from within xcode onto the image location box.
In XCode 4 (I'm using 4.6.2) you will get this confusing message if you've just moved the target's info.plist file, but not corrected the location at the top of the summary panel. Fix this and the icons will reappear, assuming they are added to the project, or if not you should now be able to drag them in without xcode insisting on making extra copies.
This tends to happen when you're starting a project and sorting out the mess of default file locations that xcode gives you. I like my project structure to be 99% the same as the file system structure.
This is an easy fix. If the image you want as your App Icon resides outside of the root of your project, when you get that dialog just click "Yes", and then click delete on the newly created file in the root, and "Move to Trash".
The reference is still there and works without a hitch, since the file will still be in the root at runtime

Unable to change location / path settings after migrating Xcode project

I've migrated an Xcode project (iOS app) from one mac to another (same Dev Account and Code Signing preferences). Now the build fails and I get errors stating that certain files (MainWindow.xib, MyappViewController.xib and InfoPlist.string) don't exist. I've already read that several people have had this problem before and tried out the answers they got, but nothing seems to work.
As I understand, the problem lies within the path preferences for the NIB files. The error messages give the files' path as Users/Meonmyoldmac/etc - which I should change, because it's an absolute path and therefore doesn't make sense on another computer. But: when I try to open those files under Groups & Files their location is already set to 'Relative to group' and their path is given as Users/Meonmynewmac/etc. - which is exactly how I actually want it to be. (Oddly enough, the file type is listed as 'Default - Unknown' )
I've already tried…
- cleaning the project
- deleting those files from the project and putting them back in again
- restarting Xcode several times
that's possibly important:
- I'm talking about a Universal iOS App, yet only iPhone files are affected; their iPad equivalents work fine
- I changed the app localization to German, so the mentioned files are located in a folder called de.lproj
- I created the project with Xcode 4 on my older Snow Leopard Mac and use Lion/Xcode 4.2 on the new one - does that play any role here?
Thanks in advance, Fruity
If you have absolute paths to some of your files, you'll need to change them to relative paths:
In the Project Navigator, locate the missing files (colored red for not being found) and highlight one of them.
Show the File Inspector
Under Location change Absolute Path to Relative to group or Relative to project,
Then next to the path, there's a little white icon, click it and choose the file's location.
Right-click on the files in Finder, select Get Info. Check that you have permission to read the files.
Edit: Just noticed the error messages refer to the old path, so it can't be a permissions problem.
Groups can have paths set as well. Select the groups and verify that their paths are correct.
In XCode 4, when you have all three panes open, select the file in the left most pane. In the right most pane, select the white document icon at the top, looking for the header "Identity and Type." Under the popup for "location" is the name of the file. To the right of that name is a tiny icon like a window. Click on that, and you can set the location of the file.
I performed the terminal search suggested by Jim yesterday, found some 'source tree: absolute' entries in project.pbxproj and tried to manipulate them, which didn't work - couldn't even open the project in Xcode afterwards - so I called it a day.
Just now I did what I already tried yesterday before posting my question: I deleted the files from the project and copied them back in again. That miraculously eliminated all red warning signs from my project and just gave me a nice green SIGABRT when I tried to run it on the simulator. Cleaned project, restarted Xcode - perfect. Oh, and I checked the targeted device family setting, found that it was set to iPhone and switched it to iPhone/iPad - no idea if that was part of the issue.
I'm not sure if that's really an answer to the problem - but the problem has vanished...
Thanks for your help!
A less-actions solution. You can change manually in the project definition file.
Close xCode
Open .xcodeproj file in a text editor: in fact it's a folder, so edit in a text editor the inside file: project.pbxproj.
Search for the string: absolute (for sourceTree param)
For each entry (file with a absolute path set), change absolute to group.
And change the path parameter to a relative path. example:
path = en.lproj/PilotInfoViewController.xib;
- Save the file and reopen xCode.
PS: Make a backup copy of your project file before doing this manipulation.

Image files not being read on iPhone

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.

XCode uses an .xib not inside the project folder

I went back to an old project and recompiled it for OS 4.1 succesfully and ran it. I was asked to add a fourth tab to the Tab Bar, but I could not set its class to the newly added ModelsVC.h/.m. [edit: because it did not appear in the class dropdown, but the other viewcontrollers were there.]
I moved the project folder to a backup folder and unzipped a months old backup of the same project. It compiles and runs until the end of viewWillAppear for the first (default) view connected to the first tab, and then does nothing more. It is still running, but nothing is shown and nothing happens.
In the console, it says "Unknown class ModelsVC in Interface Builder file."
The problem is, that class didn't exist two months ago, so why should this way old project complain about it or even know about it?
I'd like to know where to look / tell XCode to use the .xib that is inside the project folder it is currently compiling.
And if it's path-related, how do I check what paths XCode looks in when a project is loaded/compiled?
For Xcode to run a .xib file inside the project folder, You can just open your xcode, add existing file and it is there.
I think the problem why the old project still runs is that it builds incrementally. That means when it builds the first time, the .xib file was there, and when it build the second time, it doesn't need to add and build the .xib file any more. So, in the second build, even if you delete and move out the .xib file, I think it still can build
Seems a 'sloppy copy' for whatever reason (such as a quick backup to try something experimental) of a project folder causes confusion. See this.

Problem removing and re-adding an image file into my iOS4 app bundle

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.