gpt4 book ai didi

ios - 将数组发送到下一个 View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:51 25 4
gpt4 key购买 nike

在我的应用程序中,我有 4 个 View Controller (登录、欢迎、游戏 View 和结果 View )。在游戏 View 中,我有两个额外的 View (像这样)[ View 的屏幕截图链接]。我正在使用 web api 获取数据,我的数据由项目组成(每个项目有 1 个图像和 4 个字符串)。项目编号不是恒定的,因此基于项目的数量(我将其存储在数组中),我将我的 View 从一个 View 转换到另一个 View ,直到我用完所有项目。(我呈现的方式非常类似于 View 转换 sample 来自苹果。显示最后一个项目后,我使用 perform segue 转到下一个 View 。

我正在尝试解决的问题

我正在尝试创建一个额外的 View /或 View Controller ,它使用我的项目数组中的部分信息。

我的问题

为什么我的容器 View 数组为空?(_results 数组是包含项目的数组)

这是我尝试过的:

基于这个 question :

游戏 View

ContainerViewController *container = [[ContainerViewController alloc]init];
container.array = _results;
[self performSegueWithIdentifier:@"changetoResults" sender:self];

ContainerViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"items in the array - containerviewcontroller.m %@",array);
}

这是控制台:

2013-11-26 19:11:29.157 GuessTheImage[3664:70b] there are 8 , of items in the current index -gameviewcontroller.m
2013-11-26 19:12:44.439 GuessTheImage[3664:70b] items in the array - containerviewcontroller.m (null)

谢谢。

最佳答案

因为您创建的 ViewController 不是您通过 segue 转到的 ViewController。如果您想使用 segue,您可以在 prepareForSegue 方法中获取目标 ViewController(它已经存在)并根据需要对其进行调整(在您的情况下 - 添加一个数组)。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"changetoResults"])
{
ContainerViewController *vc = (ContainerViewController *)[segue destinationViewController];
vc.array = _results;
}
}

关于ios - 将数组发送到下一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20233383/

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