本文主要是介绍IOS开发(6)之UIViewController,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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
这篇关于IOS开发(6)之UIViewController的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!