以编程方式将数组复制到情节提要中的新视图 [英] Programmatically copy array to new view in Storyboard

查看:47
本文介绍了以编程方式将数组复制到情节提要中的新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在尝试将必须复制的数组复制到以编程方式创建的新视图中.我实际上已经找到了如何使用常规导航控制器语法执行此操作.我的问题是我正在使用新的情节提要板,但我不知道执行相同操作的语法.这是我的代码.

I am currently trying to copy an array I have to a new view that I am creating programmatically. I actually have found how to do this with normal navigation controller syntax. My issue is I'm using the new storyboard and I don't know the syntax to do the same thing. Here is the code I have..

CustomerListViewController *second = [[CustomerListViewController alloc] initWithNibName:@"CustomerListViewController" bundle: nil];
[second setValue:customerList.list];
// [self.navigationController pushViewController:second animated:YES];
[self performSegueWithIdentifier:@"LoginSegue" sender:self];

如您所见,

我正在以编程方式创建第二个视图控制器,并将本地数组customerList.List存储到创建的视图控制器的数组变量中.下一步是打开新创建的视图.注释掉的行是在导航控制器下打开视图的语法.下面的行是情节提要的方式,但减去指定了我创建的视图.我需要知道情节提要的语法才能与导航控制器执行相同的操作.

as you can see, I am programmatically creating the second view controller and storing the local array customerList.List to the created view controller's array variable. The next step is to open the new created view. The line commented out is the syntax to open the view under a navigation controller. The line below is the storyboard way, but minus specifying the view I created. I need to know the syntax for the storyboard to do the same thing as the navigation controller.

推荐答案

如果使用segues,则在此处创建自己的CustomerListViewController实例是没有意义的. segue本身将从情节提要中创建视图控制器,而您在此处创建的实例将不执行任何操作.

It does not make sense to create your own instance of CustomerListViewController here if you're using segues. The segue itself will create the view controller from the storyboard and the instance you have created here will do nothing.

相反,只需在此处调用performSegueWithIdentifier:sender:.然后像这样实现prepareForSegue:sender:方法:

Instead, just call performSegueWithIdentifier:sender: here. Then implement the prepareForSegue:sender: method like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"LoginSegue"]) {
        CustomerListViewController *destinationController = (CustomerListViewController *)segue.destinationViewController;
        [destinationController setValue:customerList.list];
    }
}

这篇关于以编程方式将数组复制到情节提要中的新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆