如何从其他ViewController更改AppDelegate中的RootViewController? [英] How to change RootViewController in AppDelegate From Other ViewController?
问题描述
这是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)
这里的侧面菜单是SideMenuViewController,它是contains中的一个参数,最终成为窗口的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屋!