2011年4月27日 星期三

view switcher(二)-SwitchViewControllerAppDelegate

開啓新專案, 選擇 Window-based Application, 分別建立3個UIViewController subclass (不含xib);
1. SwitchViewController
2. BlueViewController
3. YellowViewController
再建立2個xib
1. BlueView
2. YellowView

//

// SwitchViewControllerAppDelegate.h

#import

@class SwitchViewController;

@interface SwitchViewControllerAppDelegate : NSObject {

UIWindow *window;

SwitchViewController *_switchViewController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet SwitchViewController *_switchViewController;

@end

剛剛輸入的IBOutlet宣告目的是在 應用程式啓動時 將root controller(_switchViewController)的view加入到應用程式的主視窗, 所以必須建立IBOutlet

//

// SwitchViewControllerAppDelegate.m

#import "SwitchViewControllerAppDelegate.h"

#import "SwitchViewController.h"

@implementation SwitchViewControllerAppDelegate

@synthesize window;

@synthesize _switchViewController;

#pragma mark -

#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// Override point for customization after application launch.

[self.window addSubview:_switchViewController.view];

[self.window makeKeyAndVisible];

return YES;

}

- (void)dealloc {

[window release];

[_switchViewController release];

[super dealloc];

}

@end

沒有留言:

張貼留言