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 }
  • 相关阅读:
    java源码之HashMap和HashTable的异同
    java源码之HashMap
    进制转换
    java基本数据类型及其包装类
    java实例化对象的五种方法
    20 栈的压入、弹出序列
    19 包含min函数的栈
    18 顺时针打印矩阵(记忆,常忘记)
    16 树的子结构(这题多复习)
    15合并两个排序的链表
  • 原文地址:https://www.cnblogs.com/zhangdashao/p/4576251.html
Copyright © 2011-2022 走看看