如何从其他 ViewController 更改 AppDelegate 中的 RootViewController? [英] How to change RootViewController in AppDelegate From Other ViewController?

查看:29
本文介绍了如何从其他 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:

这篇关于如何从其他 ViewController 更改 AppDelegate 中的 RootViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆