UI_搭建MVC

新建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 中编写视图了。

【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/llguanli/p/8404037.html