将 NSMutableArray 从一个视图控制器复制到另一个视图控制器? [英] Copying of NSMutableArray from one viewcontroller to another viewcontroller?
问题描述
我在 FirstViewController
中有一个 NSMutableArray
声明为 firstArray
.我想将 secondArray
复制到 firstArray
中.
I have one NSMutableArray
in FirstViewController
declared as firstArray
.
I want to copy the secondArray
into firstArray
.
在 SecondViewController 中,
In the SecondViewController,
Self.FirstViewController.firstArray = self.secondArray;
当我尝试 NSLog
FirstViewController
中的 firstArray
.count 时,它显示 0.它应该在数组中有两个对象
When I attempt to NSLog
the firstArray
.count from the FirstViewController
, it display 0. It should have two objects in the array
有人可以就此提出建议吗?
Anyone can advise on this?
推荐答案
您可以选择以下解决方案之一:
You can choose one of this solutions:
- 单身
- 在
ViewControllers
之间传递数据 - 委托
您可以在这里找到您需要的所有信息:https://stackoverflow.com/a/9736559/1578927
You can find all the info you need right here: https://stackoverflow.com/a/9736559/1578927
单例示例:
static MySingleton *sharedSingleton;
+ (void)initialize
{
static BOOL initialized = NO;
if(!initialized)
{
initialized = YES;
sharedSingleton = [[MySingleton alloc] init];
}
}
这篇关于将 NSMutableArray 从一个视图控制器复制到另一个视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!