zoukankan      html  css  js  c++  java
  • 控制器的创建方式

    第一种

     1 #import "AppDelegate.h"
     2 #import "DJOneViewController.h"//新建一个空的视图控制器
     3 @interface AppDelegate ()
     4 
     5 @end
     6 
     7 @implementation AppDelegate
     8 
     9 
    10 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    11     self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    12     self.window.backgroundColor = [UIColor redColor];
    13     //1通过代码加载视图
    14     UIViewController *onectl = [[UIViewController alloc]init];
    15     onectl.view.backgroundColor = [UIColor blueColor];
    16     self.window.rootViewController = onectl;
    17   
    18     [self.window makeKeyAndVisible];
    19     return YES;
    20 }

    第二种 加载storyBoard

     1 #import "AppDelegate.h"
     2 //#import "DJOneViewController.h"
     3 #import "DJTwoViewController.h"
     4 @interface AppDelegate ()
     5 
     6 @end
     7 
     8 @implementation AppDelegate
     9 
    10 
    11 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    12 self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    13 self.window.backgroundColor = [UIColor redColor];
    14 
    15 //2-1通过storyboard加载视图
    16 UIStoryboard *twoView = [UIStoryboard storyboardWithName:@"two" bundle:nil];
    17 UIViewController *two = [twoView instantiateInitialViewController];
    18 self.window.rootViewController = two;
    19 2-2通过id传送窗口
    20 DJTwoViewController *two2 = [twoView instantiateViewControllerWithIdentifier:@"blue"];
      self.window.rootViewController = two2; 22 [self.window makeKeyAndVisible]; 23 return YES; 24 }

    //第二种 加载xib xib文件要设置视图控件 然后指定主控制器 确定class (很早之前创建方式)

     1 #import "AppDelegate.h"
     2 //#import "DJOneViewController.h"
     3 //#import "DJTwoViewController.h"
     4 #import "DJThreeViewController.h"
     5 @interface AppDelegate ()
     6 
     7 @end
     8 
     9 @implementation AppDelegate
    10 
    11 
    12 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    13 self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    14 self.window.backgroundColor = [UIColor redColor];
    15 
    16 DJThreeViewController *three = [[DJThreeViewController alloc]initWithNibName:@"Three" bundle:nil];
    17 self.window.rootViewController = three;
    18 
    19 [self.window makeKeyAndVisible];
    20 return YES;
    21 }
  • 相关阅读:
    36_Cache Aside Pattern缓存+数据库读写模式的分析
    35_亿级流量商品详情页的多级缓存架构以及架构中每一层的意义
    34_redis阶段性总结:1T以上海量数据+10万以上QPS高并发+99.99%高可用
    33_redis在实践中的一些常见问题以及优化思路(包含linux内核参数优化)
    正则表达式全部符号解释
    如何正确学习JavaScript
    2015阿里校招前端笔试题
    前端面试总结2
    前端面试总结
    通俗易懂的来讲讲DOM
  • 原文地址:https://www.cnblogs.com/zhangdashao/p/4576251.html
Copyright © 2011-2022 走看看