【问题标题】:presenting modal view controller from app delegate with storyboards使用故事板从应用程序委托呈现模态视图控制器
【发布时间】:2012-03-13 14:18:29
【问题描述】:

如果我对我的 iOS 项目中的一件事感到遗憾,那就是我从一开始就开始使用故事板。现在我很难找到合适的参考资料。

在这种特殊情况下,我只想在应用程序从 AppDelegate 完成启动后立即显示模态视图控制器。很简单,但我现在无法完成:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    AppStartViewController *appStartViewController = [[AppStartViewController alloc] init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:appStartViewController];
    [navController setModalPresentationStyle:UIModalPresentationFullScreen];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"MyInitialViewController"];
    [vc presentModalViewController:navController animated:NO];

    // Override point for customization after application launch.
    return YES;
}

任何想法出了什么问题或我的想法错误在哪里?

【问题讨论】:

    标签: ios storyboard modalviewcontroller


    【解决方案1】:

    我认为你还没有看到 vc。您首先需要展示 vc 视图控制器。

    self.window.rootViewController = vc;

    [self.window makeKeyAndVisible];

    模态视图控制器只能由另一个已经在视图上的视图控制器呈现。

    【讨论】:

    • 我认为它在视图中 - vc 是使用故事板中的视图控制器实例化的,标识符为“MyInitialViewController”。至少那是我的猜测。像您建议的那样更改代码只会导致初始视图控制器显示为模型视图控制器
    猜你喜欢
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 2020-06-25
    • 2018-12-12
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多