现在的位置: 首页 > 综合 > 正文

Converting to Storyboards Release Notes

2013年08月28日 ⁄ 综合 ⁄ 共 1537字 ⁄ 字号 评论关闭


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:

Listing 1-1  Minimal application delegate header file

#import <UIKit/UIKit.h>
@interface AppDelegate : NSObject <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

Listing 1-2  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]));
    }
}

抱歉!评论已关闭.