Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ya.. when I began iPhone dev.. the rootViewController thing threw me for a loop too. But it’s really straight forward.</p> <p>when the app starts, I create a UIWindow object in my app delegate class. Also, in that class, I have a property of type UIWindow called window;</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIWindow *w = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; self.window=w; [w release]; // other code here... } </code></pre> <p>I then create a <code>UIViewController</code> whose <code>view</code> will be the first view in the window hierarchy, this could be called the "root view controller".</p> <p>The confusing part is...that often we create a <code>UINavigationController</code> as the "root view controller" and that navigation controller has an init method that asks for a "RootViewController", which is the first viewcontroller it will place on its stack.</p> <p>So, the window gets a "root view controller", which is the <code>UINavigationController</code>, which also has a RootViewController, which is the first view controller you want to show.</p> <p>once you sort that out, its all makes sense.. I think :-) </p> <p>here is some code that does it all.. (taken from a project I have open in front of me)</p> <pre><code>//called with the app first loads and runs.. does not fire on restarts while that app was in memory - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //create the base window.. an ios thing UIWindow *w = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]]; self.window=w; [w release]; // this is the home page from the user's perspective //the UINavController wraps around the MainViewController, or better said, the MainViewController is the root view controller MainViewController *vc = [[MainViewController alloc]init]; UINavigationController *nc = [[UINavigationController alloc]initWithRootViewController:vc]; self.navigationController=nc; // I have a property on the app delegate that references the root view controller, which is my navigation controller. [nc release]; [vc release]; //show them [self.window addSubview:nc.view]; [self.window makeKeyAndVisible]; return YES; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload