开发者

(iphone) How to store images in directory structure (vs flat documents directory) and related questions

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)

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.

Here are questions.

  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)

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

  3. How do I add files to the created directory?
  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.

  5. What happens to files under documents directory and bundle when user updates the app? Since many application开发者_如何学Gos 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?

  6. So called "resource bundle" refers to the "bundle" used in above questions?

Thank you.


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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜