The morning after

Saturday, March 20, 2010

Building iPhone/iPad applications without Interface Builder

If you are wondering how to decouple Interface Builder from the development cycle and only use XCode when starting a new iPhone or iPad application, it's very easy to do:
  1. Create a new project in XCode
  2. under 'Resources' remove MainWindow.xib
  3. under 'Other Sources' edit main.m, change the fourth argument of this call:
    UIApplicationMain(argc, argv, nil, nil) to the name of your application delegate, e.g. UIApplicationMain(argc, argv, nil, @"MyAppDelegate")
  4. Now you just need to make sure your application creates and shows a window, this was part of the MainWindow.xib we deleted in step (2) and now we'll need to do this ourselves (see the code snippet below)
Creating your own window and making it visible is done in your application delegate implementation, like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *newWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[newWindow makeKeyAndVisible];
}

Note that this exact implementation does not release the created window, you'll typically want to store a reference in a class-level variable and release it when deallocating.

Labels:

0 Comments:

Post a Comment

<< Home