user4951
user4951

Reputation: 33050

What is Root View Controller

When we do things like

[self.window addSubview:switchViewController.view];

Are we setting switchViewController as the rootViewController?

Upvotes: 0

Views: 3094

Answers (1)

Actually no. rootViewController is a main controller. Callbacks such as didReceiveMemoryWarning will be sent to rootViewController only. And it must decide to whom it is addressed.

A window contain any amount of views. Some of them have UIViewControllers, some don't. So [self.window addSubview:switchViewController.view]; just add a view to a window, it doesn't know anything about its controller. The controllers should be manipulated by a rootViewController. The only way to set switchViewController as the rootViewController is to invoke something like self.rootViewController = switchViewController; in your AppDelegate file.

Upvotes: 2

Related Questions