我有一个自定义的 UIVieController 类,它不包含在任何 StoryBoard 中,我需要从这个类调用一个包含在 StoryBoard 中的 UIViewController,我尝试了很多方法来做到这一点,但它不起作用,总是得到一个NSException 因为当我尝试实例化 StoryBoard 的 UIViewController 并获得一个 nil 对象时。
我不知道为什么会这样,我真的很感谢任何帮助。
谢谢。
只是为了在这段代码中澄清,我省略了将 View 推送到 UINavigationController。
我试过了。
+(void)loadSocialMediaAppSegue:(AXISAppDelegate*)delegate withName:(NSString*)segueId{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
AXISWebViewViewController *axisWebView = [storyboard instantiateViewControllerWithIdentifier:segueId];
}
还有这个
+(void)loadSocialMediaAppSegue:(AXISAppDelegate*)delegate withName:(NSString*)segueId{
AXISWebViewViewController *axisWebView = [delegate.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:segueId];
}
最佳答案
好的,您需要做的第一件事是在 Storyboard 的 View Controller 中添加一个 identifier
,您可以打开 Storyboard 的 Identity Inspector 并填写 Storyboard id 字段。
现在您可以从任何您想要的地方调用此 UIViewController,如下所示:
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"the name of your storyboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"the id of your view controller"];
希望这可以帮助你。
关于iOS:从 Storyboard 外部的编码 UIViewController 调用 segue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24683711/