将数组中的数据在视图之间传输
我有一个类,称为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以考虑创建一个
singleton< /code>
类,您可以在应用程序中的任何位置访问该类。 Apple 文档有
创建单例类的标准方法
。您可以将Class1
设为单例类。You can consider creating a
singleton
class which you can access anywhere in your application. Apple docs have astandard approach
for creating singleton classes. You can makeClass1
a singleton class.