标签:
1 ViewController *vc = [[ViewController alloc] init];
1 ViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // 手动添加window到screen 3 self.window = [[UIWindow alloc] init]; 4 self.window.frame = [[UIScreen mainScreen] bounds]; 5 self.window.backgroundColor = [UIColor grayColor]; 6 [self.window makeKeyAndVisible]; 7 return YES; 8 }
1 // 2.取得stroyboard 2 UIStoryboard *sb = [UIStoryboard storyboardWithName:@"mysb" bundle:nil];
1 // 3.1直接使用InitialViewController 2 self.window.rootViewController = [sb instantiateInitialViewController];
1 // 4.使用ID取得controller, 设置rootViewController 2 self.window.rootViewController = [sb instantiateViewControllerWithIdentifier:@"vc2"];
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // 1.手动添加window到screen 3 self.window = [[UIWindow alloc] init]; 4 self.window.frame = [[UIScreen mainScreen] bounds]; 5 self.window.backgroundColor = [UIColor grayColor]; 6 [self.window makeKeyAndVisible]; 7 8 // 2.取得stroyboard 9 UIStoryboard *sb = [UIStoryboard storyboardWithName:@"mysb" bundle:nil]; 10 11 // 3.取出storyboar中的controller 12 // 3.1直接使用InitialViewController 13 ViewController *controller = [sb instantiateInitialViewController]; 14 15 // 3.2使用ID 16 ViewController2 *controller2 = [sb instantiateViewControllerWithIdentifier:@"vc2"]; 17 18 // 4.设置rootViewController 19 self.window.rootViewController = controller2; 20 21 return YES; 22 }
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // 1.手动添加window到screen 3 self.window = [[UIWindow alloc] init]; 4 self.window.frame = [[UIScreen mainScreen] bounds]; 5 self.window.backgroundColor = [UIColor grayColor]; 6 [self.window makeKeyAndVisible]; 7 8 // 从xib加载控制器, 设置rootViewController 9 self.window.rootViewController = [[XibViewController alloc] initWithNibName:@"myx" bundle:nil]; 10 11 return YES; 12 }
最新版的官方文档:
1 // 加载view,这是延迟加载,当需要使用view而view是空的时候调用 2 - (void)loadView { 3 NSLog(@"loadView..."); 4 self.view = [[UIView alloc] init]; 5 self.view.frame = [[UIScreen mainScreen] bounds]; 6 UILabel *label = [[UILabel alloc] init]; 7 label.frame = CGRectMake(40, 40, 100, 100); 8 label.text = @"loadView"; 9 [self.view addSubview:label]; 10 }
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // 配置window 3 self.window = [[UIWindow alloc] init]; 4 self.window.frame = [[UIScreen mainScreen] bounds]; 5 self.window.backgroundColor = [UIColor grayColor]; 6 7 // 配置storyboard中的controller为rootViewController 8 self.window.rootViewController = [[UIStoryboard storyboardWithName:@"test" bundle:nil] instantiateInitialViewController]; 9 10 // 配置xib中的controller为rootViewController,主要要使用带有loadView的controller 11 // self.window.rootViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 12 13 // 显示window 14 [self.window makeKeyAndVisible]; 15 return YES; 16 } 17
1 // 配置xib中的controller为rootViewController,主要要使用带有loadView的controller 2 self.window.rootViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
【iOS基础控件 - 14】 控制器 && 控制器的view
标签:
原文地址:http://www.cnblogs.com/kengsir/p/4281842.html