这个问题解决了吗?带有文件夹引用的图像视图 [英] is this problem resolved? image view with folder reference

查看:27
本文介绍了这个问题解决了吗?带有文件夹引用的图像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道以下描述的此问题的解决方法:

Anybody know a workaround for this problem described under:

当您将文件夹添加为引用(蓝色文件夹")时,它会将该文件夹添加到您的包中,而不仅仅是该文件夹中的文件.这意味着当您想要引用该文件夹中的文件时,您有通过执行 foldername/myfile.png 来引用它(因为您必须深入到该文件夹​​中,而不仅仅是包根目录中的文件).

"When you add the folder as a reference ("blue folder") it adds that folder to your bundle and not just the files in that folder. This means that when you want to reference a file in that folder, you have to reference it by doing foldername/myfile.png (because you have to dive into that folder, instead of just files in the root of the bundle).

我还没有找到解决这个问题的方法,所以如果你需要在这样的文件夹中引用一个文件 - 无论是在 IB 中还是像 imageNamed 这样的方法:你需要做文件夹名/文件名,否则它不会找到了."

I haven't found a way around this, so if you need to reference a file in a folder like that - be it in IB or a method like imageNamed: you need to do foldername/filename otherwise it won't be found."

它在我创建组而不是文件夹引用时有效.

It works when I create groups instead of folder references though.

哦,我想知道,如果我添加一个带有图片的文件夹并选择了为任何添加的文件夹创建组",所有的结构都会丢失,所有内容都将在我的应用程序包中的根目录中电话?因为如果我在我的开发项目中使用 finder,我可以看到 xcode 复制了我的文件夹,其中包含所有图片.但是如果它是真的并且没有保留结构,这意味着我的开发项目中的不同文件夹中不能有两个同名的图像,对吗?即使我的所有图像都在我的开发项目中的图像"文件夹中,我仍然可以在 xcode 中直接访问它们(foo.png 不是图像/foo.png),对吗?

Oh and I was wondering, if I add a folder with pictures in it with "Create groups for any added folders" selected, is all the structure going to be lost and everything will be on the root in my app bundle on the phone? Because if I go with the finder in my dev project, I can see that xcode copied my folder with all the pictures in it. But if it's true and no structure is kept, it means that I can't have two images with the same name in different folders in my dev project, correct? and even if all my images are in a folder "images" in my dev project, I still access them directly (foo.png not images/foo.png) in xcode, right?

编辑

确定添加用户路径后(感谢@Matthew Frederick)我现在可以在 IB 的下拉列表中看到我的图像的文件名,并且它们显示在界面上!问题是,它没有在下拉列表中添加文件夹(我只看到 filename.png 而不是 images/filename.png),所以当我编译时,它会查找 filename.png 而不是images/filename.png",所以它不起作用.我必须手动将图像/文件名.png 放入 IB 下拉列表中,但是图像不会显示在 IB 中...

OK after adding the User paths (thanks to @Matthew Frederick) I can now see the filename of my images in the dropdown of IB and they show up on the interface! Problem is, it does not add the folder in the dropdown (I only see filename.png not images/filename.png), so when I compile, it looks for filename.png instead of "images/filename.png", so it does not work. I have to put images/filename.png manually in the IB dropdown, but then the image does not show in IB...

推荐答案

Interface Builder 只会在目标的标头搜索路径中寻找潜在的图形/媒体,因此如果您想访问项目文件夹中没有松动的任何内容,您需要添加这些路径.

Interface Builder will only look for potential graphics/media in your target's header search paths, so if you want access to anything that's not loose in your project folder you'll need to add those paths.

幸运的是这很容易.

  • 在项目导航器中点击您的项目,然后在主要区域点击您的目标.

  • In the Project Navigator click on your project, and then in the main area click on your target.

点击构建设置标签并向下滚动到搜索路径部分.

User Header Search Paths 小节中,双击 Project 列(第 3 列上方)中的区域,将出现一个小对话框:

In the User Header Search Paths subsection double-click on the area in the Project column (3rd column over) and a small dialog will appear:

  • 单击+ 按钮,然后键入您添加的文件夹的路径(相对于项目的基本文件夹),然后单击完成.路径应以 /yourPathName 的形式指定.
  • Click the + button, then type the path to your added folders, relative to the project's base folder, then click Done. The paths should be specified in the form of /yourPathName.

噗,现在IB可以看到文件夹里面的图形了,会在各种下拉菜单中显示为folderName/imageName"等.

Poof, now IB can see the graphics inside the folder, and will present them as "folderName/imageName" in it's various dropdown menus and such.

注意:这也适用于 .h 和 .m 文件以及项目文件夹内文件夹内的任何其他内容:添加路径告诉编译器查看其他位置(因此您在我的屏幕截图,人类数据类"和机器数据类",其中我保留了由 创建的核心数据类文件发电机).

Note: This is also true for .h and .m files and anything else inside a folder inside your project's folder: adding paths tells the compiler other places to look (hence the folders you see in my screenshot, "Human Data Classes" and "Machine Data Classes," where I keep my Core Data class files as created by mogenerator).

这篇关于这个问题解决了吗?带有文件夹引用的图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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