iOS:从 Storyboard 外部的编码 UIViewController 调用 segue

标签 ios uiviewcontroller storyboard

我有一个自定义的 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/

相关文章:

swift - 在呈现给新 View Controller 之前关闭 View Controller

swift - 如何检测 UIPageViewController View 何时更改

ios - XCode 4.6 中的圆形按钮

ios - 根据 ImageView 大小更改 View 位置

iphone - UIButton 标题不出现或被剪切 - 仅最底部的标签

objective-c - 为什么我的整个 View 都在动画,而不仅仅是我的 UIImage View

ios - SwiftUI:使用变量从右到左滚动 Imageview 的动画

ios - 使用 UITableView 发出分页

ios - 从 UIViewController 导航到 SwiftUI View

ios - 在Apple Review之前获取App Store URL