Serializing/Storing a UIView and its subviews

南楼画角 提交于 2019-12-10 19:25:15

问题


I'm a relatively new iOS developer, with most of my previous experience coming from .NET. My application is a canvas like system in that there is a parent UIView that contains all the objects the user is placing/resizing/etc as subviews. I want to be able to save these positions/configurations to named files.

In .NET, I would have simply subclassed UIView, given it a "title" property, then serialized this to file, and then deserialized them to load them back, but in Cocoa I'm quite lost.

Originally I thought I could do this using NSCoding, but this doesn't seem to be a good solution for multiple file saving.

So I looked at Core Data, but I'm not sure how I can create Core Data objects of existing Cocoa UIKit classes like UIView.

I've spent a while googling and can't find any information about this kind of predicament. What should I use, and what is the best way to go about it?


回答1:


You probably could do it with NSKeyedArchiver, since UIView implements NSCoding. A more MVC-oriented design, however, would be to have the user manipulate a data model by moving the views around. To save, you'd archive the model rather than the views themselves.



来源:https://stackoverflow.com/questions/5415437/serializing-storing-a-uiview-and-its-subviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!