您的位置:首页 > 其它

源码03-02-07-LoadView

2017-03-14 17:51 169 查看


//
//  AppDelegate.m
//  07-控制器View的创建
#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

// 加载箭头指向的控制器
UIViewController *vc = [storyboard instantiateInitialViewController];

self.window.rootViewController = vc;

[self.window makeKeyAndVisible];

return YES;
}
@end


//
//  ViewController.m
//  07-控制器View的创建
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

// loadView作用:自定义控制器的view

// loadView什么时候调用:第一次使用控制器的view的时候调用

// 注意:在这个方法中如果没有自定义view,就不能获取控制器的view

// 一旦重写了这个方法,就不要调用[super loadView]
// 如果重写了这个方法,就不会去加载storyboard描述的控制器的View
- (void)loadView
{
//  self.view.backgroundColor = [UIColor redColor];

//    // 创建控制器view
self.view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
//
self.view.backgroundColor = [UIColor purpleColor];
}

//- (UIView *)view
//{
//    if (_view == nil) {
//        [self loadView];
//
//        [self viewDidLoad];
//    }
//    return _view;
//}

#pragma mark - 直接不实现就是系统默认的做法
//- (void)loadView
//{
//    // super ->  UIViewController
//    // 系统默认的做法,一定不要这样写
//    [super loadView];
//
//}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐