1 前言
IOS开发遵循MVC模型,即模型-视图-控制器。
视图是展现给用户的东西;模型是App管理的数据,也是App引擎的另一种叫法;控制器则是连接模型和视图的桥梁。今天主要介绍一下,在新建跟视图的ViewController时候,带nib文件和不带nib文件的区别。
2 UIViewController使用
上delegate的代码
.h文件
#import <UIKit/UIKit.h>
#import "RootViewController.h"
#import "ZYRootViewController.h"
@interface ZYAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
//@property (strong, nonatomic) RootViewController *rootViewController;
@property (strong, nonatomic) ZYRootViewController *rootViewController;
@end
.m文件
@synthesize window = _window;
@synthesize rootViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// self.window.backgroundColor = [UIColor whiteColor];//去掉背景色方便显示rootView
[self.window makeKeyAndVisible];
// self.rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:NULL];//无nib文件方式
self.rootViewController = [[ZYRootViewController alloc] initWithNibName:@"ZYRootViewController" bundle:NULL];//有nib文件方式
[self.window addSubview:self.rootViewController.view];
return YES;
}
运行结果:
3 结语
今天主要介绍了RootViewController的创建,希望对大家有所帮助。
Demo 下载地址:http://download.csdn.net/detail/u010013695/5290603