我试图在另一个故事板中设置视图控制器的属性(NSManagedObject)并显示它:
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];
但是当它到达
时initialView.entity= self.entity;
我得到了
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController setEntity:]: unrecognized selector sent to instance
有趣的是,
MyViewController* initialView = [[MyViewController alloc] init];
initialView.entity= self.entity;
有效,但我无法加载它,因为它应该由其故事板进行实例化。
提前致谢
答案 0 :(得分:2)
首先替换:
MyViewController* initialView = [storyboard instantiateInitialViewController];
使用:
MyViewController* initialView = [storyboard instantiateViewControllerWithIdentifier:@"ID"];
最后转到第二个故事板并转到视图控制器。将故事板ID设置为" ID"。
答案 1 :(得分:0)
确保已将MyViewcontroller连接到正确的故事板视图控制器,并将故事板标记为初始。 然后尝试像
一样投射MyViewController* initialView =(MyViewController *) [storyboard instantiateInitialViewController];