xCode 5.1 中使用xib文件做主视图
1.创建UIViewController类(下面以RootViewController为例)并添加相应的xib文件;
2.在AppDelegate类中引进RootViewController,并加载到主视图中即可;
AppDelegate.h文件内容:
#import <UIKit/UIKit.h> @class RootViewController; // 应用程序委托 @interface AppDelegate : UIResponder <UIApplicationDelegate> // 窗口 @property (strong, nonatomic) UIWindow *window; // 根视图控制器 @property (nonatomic,retain) RootViewController *viewController; @end
AppDelegate.m文件内容:
#import "AppDelegate.h" #import "RootViewController.h" @implementation AppDelegate // 让编译器帮我们实现属性的读写方法 @synthesize window; @synthesize viewController; // 重写析构函数 - (void)dealloc { self.window = nil; self.viewController = nil; [super dealloc]; } // 应用程序加载到内存后调用的方法 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // 创建窗口 self.window = [[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds] autorelease]; self.viewController = [[[RootViewController alloc] initWithNibName:nil bundle:nil] autorelease]; // 把根视图控制器 作为 窗口的 第一个视图控制器 self.window.rootViewController = self.viewController; // 显示窗口 [self.window makeKeyAndVisible]; return YES; } @end