如何在一个项目中的两个故事板之间自定义对象?

时间:2014-05-24 04:13:42

标签: ios objective-c storyboard

我的项目中有两个故事板。我通常可以从一个故事板视图导航到另一个故事板视图吗?

我正在编写如下代码

 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];

现在,我有三个按钮,并在它们上面标记,如何传递自定义对象,保存在另一个故事板的下一个控制器(“DETAIL”)中。

由于

2 个答案:

答案 0 :(得分:2)

也许这可以帮到你:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboard2" bundle:nil];
[self presentModalViewController:[storyboard instantiateViewControllerWithIdentifier:@"storyboard2initialviewcontroller"] animated:NO];

编辑:

也许这样,不确定它会有所帮助,但我会尝试:)

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"MySegue"]) {
        MyOtherViewController *destination = (MyOtherViewController *)segue.destinationViewController;
        destination.someProperty = self.someOtherProperty;
    }
}

UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];
MyOtherViewController *myViewController = (MyOtherViewController *)[secondStoryBoard instantiateViewControllerWithIdentifier:@"myOtherViewController"];

myViewController.someProperty = self.someOtherProperty;

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

答案 1 :(得分:1)

您可以传递自定义对象,如下所示

 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];

希望这有助于你