如何从其他 ViewController 更改 AppDelegate 中的 RootViewController?

问题描述:

这是 AppDelegate 中的 didFinishLaunchingWithOptions 方法.让我解释一下场景,我在我的应用程序中开发了像 facebook 这样的 sideMenu,但现在我必须根据屏幕(ViewController)更改 sideMenu 列表

This is didFinishLaunchingWithOptions Method in AppDelegate. Let me explain scenario, I have developed sideMenu like facebook in my app, but now I have to change the sideMenu list according to screens (ViewController)

这里的side Menu是SideMenuViewController,它是contain中的一个参数,最终成为window的rootViewController.

Here the side Menu is SideMenuViewController, which is an argument in contain, which ultimately becomes window's rootViewController.

所以,出现的非常基本的问题是如何更改成为windows rootViewController的控制器或变量"

SO, The very basic question arises is "How to change the controller or variable which becomes rootViewController of windows"

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

SideMenuViewController *leftMenuViewController = [[SideMenuViewController alloc] init];

self.container = [ContainerOfSideMenuByVeerViewController
                  containerWithCenterViewController:[self navigationController]
                  leftMenuViewController:leftMenuViewController];

self.window.rootViewController = self.container;

[self.window makeKeyAndVisible];

return YES;

}

如果有程序员想了解更多代码或需求,欢迎通过编辑我的代码或在评论中提供.

If any programmer wants to know more code or requirement, I do welcome to provide by editing my code or in comments.

试试这个:

<YourAppDelegateClass> *app = [[UIApplication sharedApplication] delegate];
app.window.rootViewController = <YourRootViewController>;

不要忘记包含必要的标头(例如您的 AppDelegate),否则您将获得 CE.这个似乎有效:

Don't forget to include necessary headers (your AppDelegate, for example) or you'll get CE. This one seems to work: