views:

476

answers:

1

I'm diving into iPad development and am learning a lot quickly, but everywhere I look, I have questions. After creating a new SplitView app in Xcode using the template, it generates the AppDelegate class, RootViewController class, and DetailViewController class. Along with that, it creates a .xib files for MainWinow.xib and DetailView.xib.

  1. How do these five files work together?
  2. Why is there a nib file for the DetailView, but not the RootView?
  3. When I double click on the MainWindow.xib file, Interface Builder launches without a "View" window, why?
  4. Below is the code for didFinishLaunchingWithOptions method inside the AppDelegate class. Why are we adding the splitViewController as a subview?

    (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    
    // Override point for customization after app launch    
    rootViewController.managedObjectContext = self.managedObjectContext;
    
    
    // Add the split view controller's view to the window and display.
    [window addSubview:splitViewController.view];
    [window makeKeyAndVisible];
    
    
    return YES;
    

    }

Thanks so much in advance for all your help! I still have a lot to learn, so I apologize if this question is absurd in any way. I'm going to continue researching these questions right now!

+2  A: 

MainWinow.xib is the default window created by every Cocoa touch project. It's the window all other windows are added to, usually in the AppDelegate.

AppDelegate, I'm assuming you know already. This is your base class for your Application.

SplitViewController is an UISplitViewController and it is added to MainWindow.xib for you using IB, but not added to the Window in MainView.xib until didFinishLaunchingWithOptions: is run.

By default SplitViewController manages two ViewControllers as a convenience for you. Typically these are a UITableView (called RootViewController in the template), and a UIViewController (called DetailViewController). Although you can remove these entirely if you want.

RootViewController is simply a UITableViewController. It is added to SplitViewController in IB.

DetailViewController is a UIViewController, and it is also added to IB in MainWindow.xib for you.

Why is there a nib file for the DetailView, but not the RootView?

I believe DetailView is loaded from a nib file to facilitate memory management. But it just as easily could have been created programmatically. There is not a nib for the RootView because it is already added and initialized in UISplitViewController. It could have just as easily been loaded from a xib file.

When I double click on the MainWindow.xib file, Interface Builder launches without a "View" window, why?

This default iPad template uses a UISplitViewController called SplitViewController and not a UIView Called View as other iPhone templates.

Below is the code for didFinishLaunchingWithOptions method inside the AppDelegate class. Why are we adding the splitViewController as a subview?

SplitViewController only exists in the MainWindow.xib, it's not added to Window (in MainWindow.xib). So it is added here. If it were nested in SplitViewController there would be no need to added in the AppDelegate.

This is the document you want to read

Jordan