Arya
Arya

Reputation: 145

Set Property of ViewController from Another Storyboard

I'm trying to set a property (NSManagedObject) of a view controller in another storyboard and present it:

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MySecondStoryboard" bundle:nil];
MyViewController* initialView = [storyboard instantiateInitialViewController];
initialView.entity= self.entity;
initialView.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:initialView animated:YES completion:nil];

But when it gets to

initialView.entity= self.entity;

I get

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setEntity:]: unrecognized selector sent to instance

Interestingly,

MyViewController* initialView = [[MyViewController alloc] init];
initialView.entity= self.entity;

works, but I can't load it because it should be instantiated by its storyboard.

Thanks in advance

Upvotes: 1

Views: 314

Answers (2)

JIthin
JIthin

Reputation: 1453

Make sure that you have connected the MyViewcontroller to the correct storyboard view controller, and the story board is marked as initial. then try casting like

MyViewController* initialView =(MyViewController *) [storyboard instantiateInitialViewController];

Upvotes: 0

Abdullah Shafique
Abdullah Shafique

Reputation: 6918

First replace:

MyViewController* initialView = [storyboard instantiateInitialViewController];

with:

MyViewController* initialView = [storyboard instantiateViewControllerWithIdentifier:@"ID"];

Last go to your second storyboard and go to your view controller. Set the storyboard ID to "ID".

Upvotes: 2

Related Questions