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 }
  • 相关阅读:
    心跳监控系统
    Mysql主从配置+读写分离(转)
    linux系统文件属性-硬连接、软连接
    巧用MySQL InnoDB引擎锁机制解决死锁问题(转)
    mysql数据库编码、字段编码、表编码 专题
    MySQL中select * for update锁表的问题(转)
    Android setTextColor无效_安卓setTextColor()的参数设置方式
    Android如何查看应用签名信息--微信平台开发应用的签名
    Android 生成keystore,两种方式
    MyEclipse + Maven开发Web工程的详细配置过程
  • 原文地址:https://www.cnblogs.com/zhangdashao/p/4576251.html
Copyright © 2011-2022 走看看