保存 UIView 以供下次启动(不是作为图像)
我正在构建一个带有多个 UIView 的应用程序,这些 UIView 是根据用户输入动态生成的。这些UIViews
可能包含标签、图像和文本。它们需要一些时间来生成,因此我希望用户能够在将来启动应用程序时快速加载它们,而不必再次重新绘制它们。一项要求是它们需要保持交互状态,以便用户可以继续编辑它们。
我查看了 NSKeyedArchiver
但这似乎不支持 UIImage
。另外,我无法将其另存为 PNG,因为我想保留它们的交互状态。
有什么办法可以做到这一点吗?
I am building an app with several UIViews
which are generated dynamically, based on user inputs. These UIViews
may contain labels, images and text. They take some time to generate so I would like the user to be able to load them up quickly on future launches of the app without having to redraw them again. One requirement is that they need to keep their interactive state so the user can continue to edit them.
I looked into NSKeyedArchiver
but this doesn't seem to support UIImage
. Also, I can't save it as PNG since I would like to retain their interactive state.
Is there any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该考虑将数据模型与界面分开。然后,您可以使用此存储的模型来生成界面。我知道你明确表示你不想这样做。然而,任何内置方法都必须以完全相同的方式重建 UIView。
如果模型数据的处理是问题,请尝试想出一种有效表示界面状态的方法,这样您就不必从头开始。然而,这将需要更多的工作。
You should consider keeping the model of your data separate from the interface. You can then use this stored model to generate the interface. I know you specifically said that you don't want to do this. However, any built in method is going to have to rebuild the UIViews in exactly the same way.
If the processing of the model data is the issue, try to come up with a way to efficiently represent the state of the interface so that you don't have to start from scratch. However, that will be a lot more work.