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

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

问题描述

我制作了一个具有特定功能和特定图形外观的应用程序.

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

例如,自定义 tableview 单元格从 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"文件夹中放置了蓝色版本的customcell.png",在pink"文件夹中放置了粉色版本的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",只留下了新文件夹中的 2 个副本.

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"的 nib 引用的customcell.png"图像

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

(或粉色版本)

所以,基本上我的问题是,如何使用与不同目标关联的具有相同名称的不同图像,但是有 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. 确保您的目标已被选中.

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

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天全站免登陆