Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change RootViewController in AppDelegate From Other ViewController?

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)

Here the side Menu is SideMenuViewController, which is an argument in contain, which ultimately becomes window's 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.

like image 264
Chatar Veer Suthar Avatar asked Jul 01 '13 15:07

Chatar Veer Suthar


People also ask

How do I change my initial view controller?

If you are starter like me ( both iOS and OSX mechine ) and you wanted to change the entry point within same storyboard, then, -> long press on the entry point arrow. -> drag it to the view controller you wish to make the starting point, the arrow will now move to your new screen.

How do I change the initial view controller in storyboard?

Specifying the Initial View Controllerstoryboard and select the Tab Bar Controller Scene. On the right, select the Attribute inspector. You'll find a checkbox named Is Initial View Controller. Checking this box will identify the selected view controller as the initial entry point for the storyboard you're on.


1 Answers

Try this:

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

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

like image 161
Renderhp Avatar answered Sep 30 '22 16:09

Renderhp