I have made an app with a certain functionality and a certain graphical look.
For example, a custom tableview cell is loaded from a Xib file and has a UIImageView as a background image, loaded with a Pink image ("customcell.png") from the resources group.
Now, I have duplicated the original Target to create a blue version of the app. Also, the new Target is using its own Info.plist file with its own bundle identifier.
I wanted the UIImageView inside the Xib file to use the same filename ("customcell.png"), but take a the blue version of customcell.png if the blue Target was built.
I know you can't have files with the same name in a project, even if you put it in a group (yellow folder), since that's just a logical folder.
So I created 2 blue folders (called "blue", and "pink"), each associated with the correct Target. I have put a blue version of "customcell.png" in the "blue" folder, and a pink version of "customcell.png" in the "pink" folder.
I have deleted the original "customcell.png" from the project, leaving just the 2 copies that are in the new folders.
In Interface Builder, the UIImageView has gone blank (since I deleted the original image file), so I selected "customcell.png" again from the dropdown list. It showed only 1 file of that name (not 2), and it is the blue one (don't know why).
However, when I build to any of the targets, I get an empty UIImageView and a warning:
Could not load the "customcell.png" image referenced from a nib in the bundle with identifier "com.myapp.blueversion"
(or pinkversion)
So, basically my question is, how can I use different images with the same name, associated to different targets, but having 1 Xib file that loads them appropriately?
The problem you're having is that you're trying to use the blue folders as if they were normal file system folders. The blue folders are actually just groups of files for organization in the IDE and don't represent a folder hierarchy 'under the hood'.
Take a look at how it works by right-clicking on some of the images to view them in Finder and you'll notice that files in 2 different blue group folders are actually in the same directory by default.
How to use one xib referencing the same named images for multiple targets:
Just repeat this process for each target.
When you view the xib in Xcode it will always show one version of the image, but it will be correct when you run the app.
You could try two copies of .xib, each a member of different target. .m and .h can be members of both targets, if you wish (so only .xib is duplicated).
I just posted a similiar question which might help you with this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With