Window Based App vs Single View app


Hi there,

I’m having a little trouble wrapping my head around this. When I go through the steps to create a new “Window based Application” project it creates a .XIB file called mainwindow.XIB I enter all the lines code to create a UITableViewController and set it as the rootViewController, and an empty table view appears when I build & run. Genius!

However :
If I create a different type of project, (in my case I have another side project that was created as a “Single View application” project, but I want to add a UITableViewController to it and do the exact same lines of code as above, it won’t display any picture - just a black screen - when I build & run. I ripped ALL my code out, so the only things left are in every way IDENTICAL to the Window Based Application above, and no fix.

The only difference I could find between a Window Based Application and a Single View Application was the existence of a MainWindow.XIB file - so I created one of those in the hopes that it would work, but it doesn’t. The Window Based Application has an App Delegate with a connection from delegate -> Files Owner, but my Single View app doesn’t have this. I can’t figure out a way to get it in there.

I’m totally confused about how to get anything to display. I follow the code perfectly to the letter, but because my project was initially created as a Single View and not a Window Based, I’m missing that App Delegate object and I don’t see how to add it.

There must be a way I can make this work without throwing it all out and starting from scratch. If you have any advise, please help.


I found this post on StackOverflow which seems to address the problem I’m having, but I still can’t quite get it. … p-delegate

I guess what I’m really asking is : Say you delete your mainWindow.XIB file - how can you recreate it? Here are the steps I’ve followed : Create a new mainWindow.XIB, change the class to say BNRAppDelegate, drag an NSObject to the Objects List. Change the File’s Owner class to UIApplication, connect the App Delegate Object’s “delegate” connection to Files’ Owner, connect it’s window outlet to the Window.

Now the mainWindow.XIB file has all the same objects, all the same connections, all the same classes configured, and is exactly identical in every way, but I still just get a black screen when I build & run. If anyone can offer any help, this has got me really stuck here.


Creating MainWindow.xib is a bunch of steps, and it is overall a useless construct: a big file with all kinds of arcane connections just to get a window.

Instead, the use of MainWindow.xib is being deprecated in favor of allocating and initializing a window programmatically in the app delegate. This is actually the reason you have a black screen: you don’t have a window.

You should have a code that allocates and initializes a window, sets its root view controller, and make the window visible. Without this code, nothing can appear on the screen.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    // Allocates and initializes the window 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Sets the root view controller
    BNRVideoListViewController *vc = [[BNRVideoListViewController alloc] init];
    [[self window] setRootViewController:vc];

    // Makes the window white and puts it on the screen
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    return YES;


Thanks Joe,

All I was missing was this one line :

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

Adding that fixed my black screen of death.

I’ll keep reading through the 3rd edition trying to figure it out as I go. There is a LOT to it, but I’m slowly getting a handle on it. Thanks for your help.