(iphone)如何在目录结构中存储图像(vs平面文档目录)和相关问题 [英] (iphone) How to store images in directory structure (vs flat documents directory) and related questions

查看:155
本文介绍了(iphone)如何在目录结构中存储图像(vs平面文档目录)和相关问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在我的应用程序中管理许多图像文件的好方法。

当维护的图像数量变大时,使用目录结构来保持它们似乎至关重要。为了组织图像和支持重复的图像名称)

I'm looking for a good way to manage many image files in my app.
When the number of images to maintain gets large, it seems vital to have a directory structure to hold them.(to organize images and to support duplicate image names)

由于在文件目录中存储图像的正常方式(通过将图像添加到xcode的资源文件夹)似乎不支持目录结构,

我可能需要使用一些叫做bundle的东西。

Since normal way of storing images in documents directory(by adding images to xcode's resource folder) doesn't seem to support directory structure,
I probably need to use something called bundle.

这里有问题。



  1. 我不清楚文件
    目录和束。他们是
    只是名称来指定一个iphone应用程序中的目录路径
    ?由于
    文件目录不支持
    目录结构,我猜这不是
    在iOS中的常规文件路径? (我是
    寻找一个定义或概述
    描述这两个术语足够
    帮助回答以下
    问题)

  1. It's not clear to me what's the difference between "documents directory" and "bundle". Are they just names to specify directory path inside an iphone application? Since documents directory doesn't support directory structure, I guess it's not a regular file path in iOS? (I'm looking for a definition or overview description on those two terms enough to help answering the following questions)

如何创建树结构目录来存储资源?

How do I create a tree structure directory to store resources?

在项目增长时,向
目录添加新文件的步骤(可能是xcode)是什么?注意:
问题3处理初始设置,
4处理更新。

What is the step (probably in xcode) to add new files to the directory as project grows? note: question 3 deals with initial set up, 4 deals with update.


用户更新应用程序时,文件目录和包中的文件会发生什么?由于许多
应用程序在某处存储用户数据
,所以必须使用
更新应用程序,而不会擦除
保存的用户数据。即。
文件目录和捆绑
在更新情况下表现?

What happens to files under documents directory and bundle when user updates the app? Since many applications store user data somewhere, there must be a way of updating an app without wiping out the saved user data. ie. How does "documents directory" and "bundle" behave in update situation?


谢谢。

推荐答案

您的应用是捆绑。它由NSBundle对象表示。在iOS上,这是您允许使用的唯一捆绑包;您不能创建另一个捆绑包并将其导入到您的应用程序。

Your app is a "bundle". It's represented by an NSBundle object. On iOS, this is the only bundle you are allowed to use; you can't create another bundle and import it into your app.

但是,您可以向应用程序的捆绑包中添加一个子目录。在Xcode 4中,在导航器中选择您的项目,然后单击构建阶段选项卡。添加新的构建阶段(右下),复制文件。将其移动到复制捆绑资源下方,并将其重命名为有意义的东西(复制界面图像或某些东西)。你会注意到你有一个Subpath字段,这是你的捆绑包中的目录。将该子目录中所需的文件拖动到此构建阶段,然后可以通过NSBundle,UIImage,NSData等中的常规方法访问它们。

However, you can add a subdirectory to your app's bundle. In Xcode 4, select your project in the navigator and click on the Build Phases tab. Add a new build phase (bottom right), Copy Files. Move it up just below Copy Bundle Resources, and rename it something meaningful ("copy interface images", or something). You'll notice you've got a Subpath field there - that's your directory in your bundle. Drag the files you want in that subdirectory on to this build phase, and then you can access them through the normal methods in NSBundle, UIImage, NSData and so on.

希望这更容易吗我也是。

Wish it was easier? Me too.

这篇关于(iphone)如何在目录结构中存储图像(vs平面文档目录)和相关问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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