1、xcode4.2+创建的Empty Application不再包含 MainWindow.xib文件
选择一:在代码中直接启动需要的视图,如下例:
// MyAppDelegate.h
02#import <UIKit/UIKit.h>
03@classMSCSwitchViewController;
04
05@interface MSCAppDelegate : UIResponder <UIApplicationDelegate>
06
07@property (retain, nonatomic) UIWindow *window;
08@property (nonatomic, retain) MSCSwitchViewController *switchViewController;
09
10@end
11
12// MyAppDelegate.m
13
14#import "MSCAppDelegate.h"
15#import "MSCSwitchViewController.h"
16
17@implementation MSCAppDelegate
18
19@synthesize window = _window;
20@synthesize switchViewController = _switchViewController;
21
22- (void)dealloc
23{
24[_window release];
25[_switchViewController release];
26[super dealloc];
27}
28
29- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
30{
31// 初始化window,必须用self.window,不可以使用 _window
32self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
33_switchViewController = [[MSCSwitchViewController alloc] initWithNibName:@"SwitchView"bundle:nil];
34// 这两处可以使用self.window,也可以使用 _window
35[self.window addSubview:_switchViewController.view];
36[self.window makeKeyAndVisible];
37returnYES;
38}
选择二:自己创建MainWindow.xib文件,并且指定该文件为Mian Interface:(窃以为不必这么麻烦,在多视图中,根视图最重要,不需要在传统的MainWindow中做多余的事情)