保存 UIView 以供下次启动(不是作为图像)

发布于 2024-10-16 15:52:49 字数 294 浏览 4 评论 0原文

我正在构建一个带有多个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兰花执着 2024-10-23 15:52:49

您应该考虑将数据模型与界面分开。然后,您可以使用此存储的模型来生成界面。我知道你明确表示你不想这样做。然而,任何内置方法都必须以完全相同的方式重建 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文