Ios 如何在一个项目中的两个情节提要之间自定义对象?
我有两个故事板在我的项目。我通常可以从一个故事板视图导航到另一个故事板视图 我正在编写如下代码Ios 如何在一个项目中的两个情节提要之间自定义对象?,ios,objective-c,storyboard,Ios,Objective C,Storyboard,我有两个故事板在我的项目。我通常可以从一个故事板视图导航到另一个故事板视图 我正在编写如下代码 UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Details" bundle:nil]; UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"Detail"]; // Get button tag nu
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Details" bundle:nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:@"Detail"];
// Get button tag number (or do whatever you need to do here, based on your object
NSInteger tagIndex = [(UIButton *)sender tag];
vc.modalTransitionStyle =UIModalTransitionStyleFlipHorizontal;
[self.navigationController pushViewController:vc animated:YES];
现在,我有三个按钮,上面有标签,我怎样才能将保存在数组中的自定义对象传递给另一个故事板的下一个控制器(“细节”)
谢谢也许这可以帮助您:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboard2" bundle:nil];
[self presentModalViewController:[storyboard instantiateViewControllerWithIdentifier:@"storyboard2initialviewcontroller"] animated:NO];
编辑:
也许像这样,我不确定是否会有帮助,但我会试试:)
及
您可以像下面这样传递自定义对象
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Details" bundle:nil];
HomeViewController *homeVC = [storyBoard instantiateViewControllerWithIdentifier:@"view2"];
// here I am passing string to the another controller (i.e HomeViewController), you can pass any object that you want
homeVC.info = @"This is test string";
[self.navigationController pushViewController:homeVC animated:YES];
希望这对您有所帮助关于在控制器之间传递数据,有成千上万的问题和答案,您应该查看它们。这两个控制器位于不同的故事板中这一事实无关紧要。你所需要传递的数据就是对下一个控制器(你有,vc)的引用。我知道,但这是一个例外情况,意味着在两个不同的存储板之间,我怎么能这样做?正如我所说的,这是无关的。传递数据是一个两步过程。首先,获取一个你要传递给的控制器的引用(你有vc),然后,将你在传递给的控制器中创建的属性值设置为你要传递的当前控制器中的某个值。对不起,你没有正确阅读我的问题,亲爱的。你所做的是错误的。
UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];
MyOtherViewController *myViewController = (MyOtherViewController *)[secondStoryBoard instantiateViewControllerWithIdentifier:@"myOtherViewController"];
myViewController.someProperty = self.someOtherProperty;
[self.navigationController pushViewController:myViewController animated:YES];
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Details" bundle:nil];
HomeViewController *homeVC = [storyBoard instantiateViewControllerWithIdentifier:@"view2"];
// here I am passing string to the another controller (i.e HomeViewController), you can pass any object that you want
homeVC.info = @"This is test string";
[self.navigationController pushViewController:homeVC animated:YES];