将数组中的数据在视图之间传输

发布于 2024-11-15 20:31:43 字数 315 浏览 8 评论 0原文

我有一个类,称为 Class1,它包含一个数组,称为 array1,作为属性,我保留并合成它。

我想将对象添加到该数组中,其中包含从其他视图获得的值。因此,对于每个视图,我引用 Class1,创建一个对象,然后将值添加到 array1 并为该特定视图显示它。这有效!

当我进入新视图时,我需要重新初始化 array1 以将新对象复制到其中(或者它会给我一个错误,指出 array1 为空),但是先前的值(存储在先前视图中的值)将丢失。我知道“保留”是针对特定类的,并且数组不会在程序的整个过程中保留值。

我该怎么办?

I have a class, call it Class1, which contains an array, call it array1, as a property, and I retain and synthesize it.

I want to add objects to that array with values I get from other views. So for each view, I reference Class1, create an object, and I add the value to array1 and display it for that particular view. This works!

When I go to the new view, I am required to reinitialize array1 to copy the new objects to it (or it gives me an error that array1 is null), but the previous value (the value which was stored in the previous views) is lost. I understand that "retain" is for a specific class, and the array does not retain values for the whole course of the program.

How do I go about this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

深海夜未眠 2024-11-22 20:31:43

您可以考虑创建一个 singleton< /code>类,您可以在应用程序中的任何位置访问该类。 Apple 文档有 创建单例类的标准方法。您可以将 Class1 设为单例类。

You can consider creating a singleton class which you can access anywhere in your application. Apple docs have a standard approach for creating singleton classes. You can make Class1 a singleton class.

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