Xcode 4:多个目标、多个资源文件夹,其中包含同名图像以与共享 Xib 一起使用?
我制作了一个具有特定功能和特定图形外观的应用程序。
例如,自定义表格视图单元格从 Xib 文件加载,并具有 UIImageView 作为背景图像,并从资源组加载粉红色图像(“customcell.png”)。
现在,我复制了原始 Target 以创建应用程序的蓝色版本。 此外,新的 Target 使用自己的 Info.plist 文件和自己的包标识符。
我希望 Xib 文件内的 UIImageView 使用相同的文件名(“customcell.png”),但如果构建了蓝色目标,则采用蓝色版本的 customcell.png。
我知道项目中不能有同名的文件,即使您将其放入组(黄色文件夹)中,因为这只是一个逻辑文件夹。
因此,我创建了 2 个蓝色文件夹(称为“蓝色”和“粉色”),每个文件夹都与正确的目标相关联。 我已将蓝色版本的“customcell.png”放入“蓝色”文件夹中,将粉色版本的“customcell.png”放入“粉红色”文件夹中。
我已从项目中删除了原始的“customcell.png”,只留下新文件夹中的 2 个副本。
在 Interface Builder 中,UIImageView 已变为空白(因为我删除了原始图像文件),因此我再次从下拉列表中选择“customcell.png”。 它只显示 1 个该名称的文件(不是 2 个),而且是蓝色的文件(不知道为什么)。
但是,当我构建任何目标时,我会收到一个空的 UIImageView 和一条警告:
无法加载从标识符为“com.myapp.blueversion”的包中的笔尖引用的“customcell.png”图像
(或pinkversion)
的包中的笔尖引用的“customcell.png”图像所以,基本上我的问题是, 如何使用与不同目标关联的同名不同图像, 但是有 1 个 Xib 文件可以正确加载它们吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您遇到的问题是您尝试使用蓝色文件夹,就好像它们是普通文件系统文件夹一样。蓝色文件夹实际上只是 IDE 中用于组织的文件组,并不代表“幕后”的文件夹层次结构。
右键单击一些图像以在 Finder 中查看它们,看看它是如何工作的,您会注意到默认情况下 2 个不同的蓝色组文件夹中的文件实际上位于同一目录中。
如何使用一个 xib 为多个目标引用相同命名的图像:
AppDelegate 已找到,可能以您的目标命名。
只需对每个目标重复此过程即可。
当您在 Xcode 中查看 xib 时,它将始终显示图像的一个版本,但当您运行应用程序时它将是正确的。
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:
AppDelegate is found, probably naming it after your target.
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.
您可以尝试 .xib 的两个副本,每个副本都是不同目标的成员。
如果您愿意,.m 和 .h 可以是两个目标的成员(因此只有 .xib 是重复的)。
我刚刚发布了一个类似问题 这可能会帮助你。
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.
我在使用蓝色文件夹时遇到了问题,我不确定它们应该如何工作!
我对我的应用程序的免费和付费版本使用单独的目标,这就是我分离不同图标文件的方式(很麻烦,因为它们必须有特定的名称)
我的文件系统如下所示:
我将 IconsPaid 和 IconsFree 文件夹拖到 XCode 并将内容分配给 .相关目标
I've had problems with the blue folders, I'm not sure how they are supposed to work!
I use separate targets for a free and paid version of my app, and this is how I separate the different icon files (troublesome because they have to have certain names)
My file system looks like this:
I then drag the IconsPaid and IconsFree folders to XCode and assign the contents to the relevant targets
我也有同样的问题。
我通过重命名包含我想要显示的目标图像的文件夹,使其成为按字母顺序排列的第一个目标,成功地从一个目标传递到另一个目标。
I was having the same issue.
I managed to pass from one target to another by renaming the folder containing the images of the target I wanted to be shown so that it becomes the first in alphabetical order.