ios开发-控制器的创建方式
2015-04-12 22:44
295 查看
1.文件结构
Two.storyboard
MJThree5345.xib
2.MJAppDelegate.m
// MJAppDelegate.m #import "MJAppDelegate.h" #import "MJTwoViewController.h" #import "MJOneViewController.h" #import "MJThreeViewController.h" // 蓝色\灰色 @implementation MJAppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //window的大小占据整个窗口 self.window.backgroundColor = [UIColor whiteColor]; // MJThreeViewController *three = [[MJThreeViewController alloc] initWithNibName:@"MJThree5345" bundle:nil]; // self.window.rootViewController = three; // [self test1]; [self test2]; [self.window makeKeyAndVisible]; return YES; } - (void)test1 { // 加载storyboard UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Two" bundle:nil]; //nil默认就是mbundle // 创建storyboard里面灰色的控制器 // UIViewController *vc = [storyboard instantiateInitialViewController]; //就是箭头所指的那个控制器 件storyboard的class属性便知道返回的是个 UIViewController类型的对象 // MJTwoViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"pink"]; MJTwoViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"pink"]; self.window.rootViewController = vc; NSLog(@"%@", vc); } -(void)test2 { MJOneViewController *one = [[MJOneViewController alloc] init]; one.view.backgroundColor = [UIColor blueColor]; self.window.rootViewController = one; MJTwoViewController *two = [[MJTwoViewController alloc] init]; two.view.backgroundColor = [UIColor blueColor]; self.window.rootViewController = two; } - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - (void)applicationDidEnterBackground:(UIApplication *)application { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - (void)applicationWillEnterForeground:(UIApplication *)application { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - (void)applicationDidBecomeActive:(UIApplication *)application { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } @end
3.运行结果
3.1调用test2方法运行结果
[selftest2];3.2调用test1方法运行结果
[selftest1];3.3代码创建
MJThreeViewController *three = [[MJThreeViewControlleralloc]相关文章推荐
- iOS开发UI篇—0408控制器的三种创建方式
- 【iOS开发-73】创建控制器的3种方式、深入了解view的创建和加载顺序
- ios-day11-02(控制器的多种创建方式。init方法创建、通过storyboard的创建、通过xib创建)
- IOS第12天(1,UIViewController控制器的创建的 三种方式,和第一个view创建)
- ios-创建根视图控制器的三种方式
- 【iOS开发-28】制造一个UITabBarController标签控制器、定制UITabBarItem文字图片的6种方式以及More讲解
- IOS开发OC代码中创建Swift编写的视图控制器
- iOS开发UI篇—控制器的View的创建
- iOS 控制器的三种创建方式
- ios 导航控制器(navigationController)代码方式创建
- 详解iOS开发中使用storyboard创建导航控制器的方法
- iOS开发中的错误整理,启动图片设置了没有效果;单独创建xib需要注意的事项;图片取消系统渲染的快捷方式
- ios-day11-06(使用代码的方式创建导航控制器——UINavigationController、使用导航控制器管理其他控制器)
- iOS开发UI篇—使用storyboard创建导航控制器以及控制器的生命周期
- 详解iOS开发获取当前控制器的正取方式
- iOS开发中控制器切换方式Modal
- iOS开发---AV Foundation之视频捕捉(3)__创建捕捉控制器
- ios开发之控制器View的多种创建 -- 详解
- iOS开发UI篇—控制器的创建
- 【iOS开发-79】利用Modal方式实现控制器之间的跳转