Storyboarding is a new way to create user interfaces for iOS applications, beginning with iOS 5 and Xcode 4.2. Using storyboards, you can design the view controllers that compose your application as scenes in the Xcode design canvas and visually define the navigation between the scenes using segues.
There are a few steps you need to take to convert an existing iOS application project to use storyboards. In addition, there are other new patterns you can adopt.
Configure the Application Delegate
The application delegate is responsible for loading the storyboard and managing the window. You need to specify the name of the application delegate class in UIApplicationMain
, and ensure that the application delegate has a property called window
.
If you don’t have an existing application delegate class, you need to create one. A minimal implementation would look like this:
Minimal application delegate header file
#import <UIKit/UIKit.h> |
@interface AppDelegate : NSObject <UIApplicationDelegate> |
@property (strong, nonatomic) UIWindow *window; |
@end |
Minimal application delegate implementation file
#import "AppDelegate.h" |
@implementation AppDelegate |
@synthesize window = _window; |
@end |
In the main.m
file, set the application delegate class in UIApplicationMain
.
Your existing main.m file probably looks something like this:
#import <UIKit/UIKit.h> |
|
int main(int argc, char *argv[]) { |
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
int retVal = UIApplicationMain(argc, argv, nil, nil); |
[pool release]; |
return retVal; |
} |
Change it to look like this:
#import <UIKit/UIKit.h> |
#import "AppDelegate.h" |
|
int main(int argc, char *argv[]) { |
|
@autoreleasepool { |
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); |
} |
} |