iOS: 如何从另一个视图控制器调用根控制器

iOS: How to call root controller from another view controller

以下代码用于从 AppDelegate 调用根控制器。但是,当我将它放在单独的登录 View Controller 中时,它不起作用。成功登录后,我想加载常规的 View Controller。但是在登录 VC 中,它不会加载主视图控制器。它继续显示登录 VC 尽管方法中的 NSLog 显示它正在被解雇。

感谢您提供有关从另一个 VC 加载根视图控制器的正确方法的任何建议。

    - (void)presentMainInterface
    {
NSLog(@"presenting main interface");
        self.window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
    }

试试这个

UIWindow *window =  [[[UIApplication sharedApplication] windows] firstObject];
window.rootViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];