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 logging 配置文件
    oracle exception使用
    java keytool 用法
    【转】ant学习笔记之(ant执行命令的详细参数和Ant自带的系统属性)
    [转]Ivy入门学习
    关于java.nio.Buffer的API
    如何查看LINUX操作系统是多少位的
    Linux cpio命令的使用
    window.open()使用参考
    【原创】个人站点建设(待续)
  • 原文地址:https://www.cnblogs.com/zhangdashao/p/4576251.html
Copyright © 2011-2022 走看看