0

Is it possible to pass data between storyboards in objective-c with segue when the application is not made from a master detail template?

The only examples I have seen is the one with master detail views.

matsmats
  • 502
  • 3
  • 12

1 Answers1

0

Yes, it is. You could implement prepareForSegue:sender: in the viewController you are segueing from, like so:

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

This will get called before your segue is performed, giving you a hook into the viewController you are segueing to.

Edit:

I didn't realise your ViewControllers were in different Storyboard. This question has already been pretty much answered, here: https://stackoverflow.com/a/9610972/1716763

You wouldn't actually be using a segue though, you would do things programatically and either push your second view controller onto the navigation stack, or present it modally.

I've adapted some of the code from @Inafziger's answer to fit your example:

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

myViewController.someProperty = self.someOtherProperty;

[self.navigationController pushViewController:myViewController animated:YES];
Community
  • 1
  • 1
JoeFryer
  • 2,751
  • 1
  • 18
  • 23