标签:ui uiviewcontroller mvc window uiview
新建RootViewController 继承于 UIViewController
新建RootView 继承于 UIView
AppDelegate.m 中引入 #import "RootViewController.h"
#pragma mark - 重写
#pragma mark dealloc
- (void)dealloc
{
[_window release];
[super dealloc];
}
//设置window
self.window = [[[UIWindow alloc] init] autorelease];
self.window.frame = [UIScreen mainScreen].bounds;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
// 设置根视图控制器
RootViewController *rootVC = [[RootViewController alloc] init];
self.window.rootViewController = rootVC;
[rootVC release];
RootViewController.m 中引入 #import "RootView.h"
@interface RootViewController ()
@property (nonatomic, retain) RootView *rootView;
@end
#pragma mark - 重写
#pragma mark dealloc
- (void)dealloc
{
[_rootView release];
[super dealloc];
}
编写 loadView 函数,函数中永远只写三句话
- (void)loadView
{
// 设置当前视图为根视图
self.rootView = [[RootView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.view = self.rootView;
[_rootView release];
}
可以在 RootView.m 中编写视图了。
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:ui uiviewcontroller mvc window uiview
原文地址:http://blog.csdn.net/yadong_zhao/article/details/46756493