开发者

How do I save an NSMutableArray w/ UIImgeViews to the iPhone's document direcory

I have an NSMutableArray that holds multiple and changing amounts (that's why I am using an NSMutableArray) of UIImageView's that I want to save and also in return load开发者_JS百科 when my app quits and loads. Also, how would I then, after my app loads, get the image viws out of the array


You should consult the Core Data Programming Guide and follow the tutorials there. It will teach you how to serialize and deserialize data structures and views.

http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html


Core Data might be overkill. Id just use archive the mutable array like Tomen said.

Note that UIImageView (and the rest of the views, I believe) don't really support serialization from my experience. They only claim to support the NSCoding protocol because initWithCoder is used with loading NIB files. I wouldn't try to save the whole view, I'd only save the images. You'll probably need to retrieve the UIImage from the UIImageView, then get the CGImage from that, then get the NSData object for the bitmap from that. Also:

Because image objects are immutable, they also do not provide direct access to their underlying image data. However, you can get an NSData object containing either a PNG or JPEG representation of the image data using the UIImagePNGRepresentation and UIImageJPEGRepresentation functions.

To archive the NSMutableArray the items in the array need to support encodeWithCoder (Which NSData does) so you may just want to build a new array with the NSData objects.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜