在没有segue的故事板之间传递数据

时间:2014-05-22 13:26:14

标签: objective-c ios7 storyboard

您好,我有两个故事板。让我们称它们为storyboard1和storyboard2。

我想将数据从storyboard1传递到storyboard2,这是我的代码。

在storyboard1中:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"IndicesDetail" bundle:nil];
DataIntegrationIndexDetailViewController *cl =   (DataIntegrationIndexDetailViewController *)[sb instantiateViewControllerWithIdentifier:@"indicesDetail"];

cl.transitioningDelegate = self;

[self presentViewController:cl animated:YES completion:nil];

在storyboard2中,我调用了这样的值:

NSLog(@"sel index:%@",_delegate.selectedIndexCode);

我得到的结果为空。

我也在storyboard1中尝试这样:

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"IndicesDetail" bundle:nil];
DataIntegrationIndexDetailViewController *cl = (DataIntegrationIndexDetailViewController *)[sb instantiateViewControllerWithIdentifier:@"indicesDetail"];

cl.selectedIndex = @"test";

[self presentViewController:cl animated:YES completion:nil];

但它给了我一个错误。

那么我如何将数据从一个故事板传递到另一个故事板?

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

这样做的一种方法是使用单例类......

http://www.galloway.me.uk/tutorials/singleton-classes/

答案 2 :(得分:0)

尝试:

[self.navigationController pushViewController:cl animated:YES]; 

而不是[self presentViewController]

相关问题