详解iOS的UI开发中控制器的创建方法

2020-01-14 17:04:46王旭

详解iOS的UI开发中控制器的创建方法

实现代码:

 

复制代码
#import "YYAppDelegate.h"
#import "YYViewController.h"

 

@implementation YYAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    
    //1.加载storyboard
    UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"test" bundle:nil];
    
    //2.创建指定的控制器
    
    UIViewController *controller=[storyboard instantiateViewControllerWithIdentifier:@"one"];
    //3.设置控制器为Window的根控制器
    self.window.rootViewController=controller;
    
    [self.window makeKeyAndVisible];
    return YES;
}

 


 

三、第三种创建方式(使用xib)

1.新建一个xib文件,命名为two.xib。

2.创建过程和注意点

(1)创建代码:

 

复制代码
#import "YYAppDelegate.h"