gpt4 book ai didi

ios - 将 NSMutableArray 从一个 View Controller 复制到另一个 View Controller ?

转载 作者:行者123 更新时间:2023-11-28 22:33:54 25 4
gpt4 key购买 nike

我在 FirstViewController 中有一个 NSMutableArray 声明为 firstArray。我想将 secondArray 复制到 firstArray 中。

在 SecondViewController 中,

Self.FirstViewController.firstArray = self.secondArray;

当我尝试 NSLog firstArray.count 来自 FirstViewController 时,它显示 0。数组中应该有两个对象

有人可以就此提出建议吗?

最佳答案

您可以选择以下解决方案之一:

  1. 单例
  2. ViewControllers 之间传递数据
  3. 代表团

您可以在这里找到您需要的所有信息:https://stackoverflow.com/a/9736559/1578927

单例示例:

static MySingleton *sharedSingleton;

+ (void)initialize
{
static BOOL initialized = NO;
if(!initialized)
{
initialized = YES;
sharedSingleton = [[MySingleton alloc] init];
}
}

关于ios - 将 NSMutableArray 从一个 View Controller 复制到另一个 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16670859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com