Cocoa in the Shell

[iOS] Going XIBless

If like me you don’t like to use Interface Builder when you are coding for iPhone, this post is for you. I’ll show you how you can remove the default MainWindow.xib, so that all your application is done by code.

  • First, that’s obvious, delete the MainWindow.xib file.

  • Then edit your target configuration (CMD + ALT + e) go to the Properties tab and remove the reference to the xib file you just deleted on the Main Nib File line.

  • Modify your main.m file by changing the last parameter of the UIApplicationMain() function to a NSString with the name of your application delegate, like this :

    int retVal = UIApplicationMain(argc, argv, nil, @“XibLessAppDelegate”);

  • Last, in your application delegate, edit the didFinishLaunchingWithOptions method to create your UIWindow

    _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Add a view [_window makeKeyAndVisible];

Don’t forget to release the window in your dealloc method.

And that’s it, you are free from Interface Builder, happy coding.