您在 appDelegate 类中指定根视图控制器。它应该看起来像这样:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:@"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
您需要添加的重要行是:
self.viewController = [[[ViewController alloc] initWithNibName:@"theNameOfMyXib" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
在 initWithNibName 下,您输入创建界面的 xib 的名称。
注意:autorelease
仅当您的项目不使用 ARC时才添加。