Xcode 4:多个目标,多个资源文件夹中具有与共享Xib一起使用的相同名称的图像? [英] Xcode 4: Multiple Targets, Multiple Resources Folders with images of the same name to use with a shared Xib?

查看:163
本文介绍了Xcode 4:多个目标,多个资源文件夹中具有与共享Xib一起使用的相同名称的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作的应用程序具有某些功能和图形外观.

I have made an app with a certain functionality and a certain graphical look.

例如,从Xib文件加载自定义表格视图单元,并将UIImageView作为背景图像,并从资源组加载了粉红色图像("customcell.png").

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.

现在,我已经复制了原始Target来创建应用的蓝色版本. 另外,新的Target使用其自己的Info.plist文件和其捆绑包标识符.

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.

我希望Xib文件中的UIImageView使用相同的文件名("customcell.png"),但是如果构建了蓝色目标,则采用蓝色版本的customcell.png.

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.

因此,我创建了2个蓝色文件夹(分别称为"blue"和"pink"),每个文件夹都与正确的Target关联. 我在蓝色"文件夹中放置了蓝色版本的"customcell.png",在粉红色"文件夹中放置了粉红色版本的"customcell.png".

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.

我已从项目中删除了原始的"customcell.png",仅保留了两个新文件夹中的副本.

I have deleted the original "customcell.png" from the project, leaving just the 2 copies that are in the new folders.

在Interface Builder中,UIImageView变为空白(因为我删除了原始图像文件),因此我从下拉列表中再次选择了"customcell.png". 它只显示了该名称的1个文件(不是2),而它是蓝色的(不知道为什么).

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).

但是,当我构建到任何目标时,都会得到一个空的UIImageView和一个警告:

However, when I build to any of the targets, I get an empty UIImageView and a warning:

无法加载标识符为"com.myapp.blueversion"的捆绑包中笔尖引用的"customcell.png"图像

Could not load the "customcell.png" image referenced from a nib in the bundle with identifier "com.myapp.blueversion"

(或pinkversion)

(or pinkversion)

所以,基本上我的问题是, 如何使用与相同目标相关联的具有相同名称的不同图像, 但是有1个Xib文件可以正确加载它们?

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?

推荐答案

您遇到的问题是,您试图像使用普通文件系统文件夹一样使用蓝色文件夹.蓝色文件夹实际上只是在IDE中用于组织的文件组,并不代表幕后"的文件夹层次结构.

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'.

通过右键单击某些图像以在Finder中查看它们来查看其工作原理,您会发现默认情况下2个不同的蓝色组文件夹中的文件实际上位于同一目录中.

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.

如何使用一个xib引用相同命名图像的多个目标:

  1. 在Finder中,在与 找到AppDelegate,可能将其命名为您的目标之后.
  2. 将该目标的所有图像存储在该文件夹中.
  3. 在左上方窗格中右键单击项目的主组/文件夹,然后使用将文件添加到'XcodeProjectName'...".
  4. 在出现的上方窗格中,找到并选择您刚刚在文件系统上创建的文件夹.
  5. 由于文件已经存在于您指定的位置,因此您可以保留目标"框为选中状态或未选中状态.
  6. 保留选中的为任何添加的文件夹创建组"以创建蓝色的组文件夹.
  7. 确保已检查目标.
  1. In Finder, create a new folder in the same directory where the AppDelegate is found, probably naming it after your target.
  2. Store all your images for that target in that folder.
  3. Right-click the project's main group/folder in the top left pane and use "Add Files to 'XcodeProjectName'…".
  4. In the appearing upper pane, find and select the folder you just created on the file system.
  5. You can leave the Destination box checked or unchecked, since the files already exist at the location you specified.
  6. Keep 'Create groups for any added folders' selected to create a blue group folders.
  7. Make sure your target is checked.

只需对每个目标重复此过程.

Just repeat this process for each target.

在Xcode中查看xib时,它将始终显示该图像的一个版本,但是在运行该应用程序时它是正确的.

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.

这篇关于Xcode 4:多个目标,多个资源文件夹中具有与共享Xib一起使用的相同名称的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆