1:新建一个基于windowbase的程序。你会发现它只有一个MainWindow.xib,打开这个文件,拖拽一个View Controller控件到下图的MainWindow.xib窗口。
2:右键单击Classes文件夹,为项目添加新的文件。如下图:
选择文件类型为Cocoa Touch Class,注意勾选上Targeted for iPad以及With XIB for user interface(产生xib文件)
点击确定并给类起个名字,我起的是TestViewController,回到工程会发现多了3个文件:TestViewController.h, TestViewController.m,TestViewController.xib
最好将这个xib文件拖入到Resources文件夹里。
3:双击在interface builder中打开MainWindow.xib,在右侧的悬浮窗口里面的最上面的3个标签,分别选中第一个标签(属性标签)并在nib name那一栏点击三角图标在弹出的选项中选择TestViewController,这样就将MainWindow.xib和TestViewController.xib关联起来了。再选择第4个标签(ID标签)并点击Class的三角图标在弹出的类里面选中TestViewController,这样就将TestViewController.xib和TestViewController类关联起来了。
4:在XXXAppDelegate.h中添加如下代码,蓝色字体为新增代码
#import <UIKit/UIKit.h>
@class TestViewController;
@interface WindowBaseTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
TestViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet TestViewController *viewController;
@end
在XXXAppDelegate.m中添加如下代码,
#import "WindowBaseTestAppDelegate.h"
#import "TestViewController.h"
@implementation WindowBaseTestAppDelegate
@synthesize window;
@synthesize viewController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[window addSubview:viewController.view];
[self.window makeKeyAndVisible];
return YES;
}
...
- (void)dealloc {
[viewController release];
[window release];
[super dealloc];
}
5:打开MainWindow.xib文件,鼠标左键单击Window Base ..之后鼠标右键按住它拖拽到View Con..在弹出的窗口中选中viewController,保存之。
到这里算是大功告成了。ps:为了使得效果明显一点,你最好给TestViewController.xib文件添加一个控件什么的。