IOS第12天(1,UIViewController控制器的创建的 三种方式,和第一个view创建)

*************HMAppDelegate.m中

@implementation HMAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    
    //storyboard
   [self  vcFromStoryboard];
    
    //代码
//    HMOneViewController *vc = [[HMOneViewController alloc] init];
//    vc.view.backgroundColor = [UIColor grayColor];
//
//    self.window.rootViewController = vc;
   
    //xib
    HMThreeViewController *threeVc = [[HMThreeViewController alloc] initWithNibName:@"Three168" bundle:nil];
    self.window.rootViewController = threeVc;
    [self.window makeKeyAndVisible];
    return YES;
}

//来自storyboard控制器
-(void)vcFromStoryboard{
    //设置UIWindow根控制器
    
    //第一方法 从storyboard获取控制器
    //1.1获取storyboard对象
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Test" bundle:nil];
    
    //1.2获取storyboard的第一个控制器(箭头所指的控制器)
    //UIViewController *vc = [storyboard instantiateInitialViewController];
    
    //获取storyborad指定id的控制器
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecordVC"];
    
    NSLog(@"%@",vc);
    
    //1.3设置窗口的根控制器
    self.window.rootViewController = vc;
}


***第一个view的创建

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor purpleColor];
    
    //HMOneViewController *oneVc = [[HMOneViewController alloc] initWithNibName:@"OneView168" bundle:nil];
    
    //HMOneViewController *oneVc = [[HMOneViewController alloc] initWithNibName:@"HMOneView" bundle:nil];
    
    //1.如果没有指定xib ,默认会查找与控制器名Controller以前的文字的xib(HMOneView.xib)
    //2.如果没有HMOneView.xib 接着就找与控制器同名xib(HMOneViewController.xib)
    //3.如果没有找与控制器同名的xib,自己创建一个空白view
    //   UIView *view = [UIView allloc] init]; oneVc.view = view
    
    HMOneViewController *oneVc = [[HMOneViewController alloc] init];
    self.window.rootViewController = oneVc;
    NSLog(@"aaaaaaaaaa");
    [self.window makeKeyAndVisible];
    NSLog(@"bbbbbbbbbb");
    
    //viewDidLoad
    //aaaaa
    //bbbbb
    
    //aaaaa
    //viewDidLoad
    //bbbbb
    
    
   
    return YES;
}

 

转载于:https://www.cnblogs.com/ios-g/p/4755528.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值