首页 > 代码库 > 源码03-02-07-LoadView
源码03-02-07-LoadView
//// 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
源码03-02-07-LoadView
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。