[Objective-C] 019_UIVIewController
2015-08-30 22:33
585 查看
UIViewController是iOS程序中的一个重要组成部分,对应MVC设计模式的C,它管理着程序中的众多视图,何时加载视图,视图何时消,界面的旋转等。
1.UIViewController 创建与初始化
[1].通过nib文件创建与初始化
[2].自定义创建与初始化
2.UIViewController 旋转方向控制
iOS6之前,shouldAutorotateToInterfaceOrientation方法单独控制UIViewController的方向。
iOS6及更高,重写这个2个方法,iOS6里面要旋转还有一些需要注意的地方,需要在Info.plist文件里面添加Supported interface orientations 程序支持的方向.
3.UIViewController 切换
UIViewController自身之间的调用
UINavigationControlle导航控制器的Controller来控制ViewContrller之间的切换(层次逻辑性的ViewContrller之间的切换)
从以上几点可以看出,UIViewController 之间的切换管理,正确的做法是"谁污染谁治理"。
本站文章为 宝宝巴士 SD.Team 原创,转载务必在明显处注明:(作者官方网站: 宝宝巴士 )
转载自【宝宝巴士SuperDo团队】 原文链接: /article/6669157.html
1.UIViewController 创建与初始化
[1].通过nib文件创建与初始化
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; UIViewController *test = [[TestViewController alloc] initWithNibName:@"test" bundle:nil]; self.window.rootViewController = test; [self.window makeKeyAndVisible]; return YES; }
[2].自定义创建与初始化
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; UIViewController *test = [[TestViewController alloc] init]; self.window.rootViewController = test; [self.window makeKeyAndVisible]; return YES; }
2.UIViewController 旋转方向控制
iOS6之前,shouldAutorotateToInterfaceOrientation方法单独控制UIViewController的方向。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); }
iOS6及更高,重写这个2个方法,iOS6里面要旋转还有一些需要注意的地方,需要在Info.plist文件里面添加Supported interface orientations 程序支持的方向.
- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait;//竖立 }
3.UIViewController 切换
UIViewController自身之间的调用
UIViewController *test = [[UIViewController alloc] init]; //跳转 test [self.window.rootViewController presentViewController:test animated:YES completion:^{ NSLog(@"present 完成"); }]; //返回到self (test controller消失) [self.window.rootViewController dismissViewControllerAnimated:YES completion:^{ NSLog(@"dismiss 完成"); }];
UINavigationControlle导航控制器的Controller来控制ViewContrller之间的切换(层次逻辑性的ViewContrller之间的切换)
//跳转 [self.navigationController pushViewController:test animated:YES]; //返回 [self.navigationController popViewControllerAnimated:YES];
从以上几点可以看出,UIViewController 之间的切换管理,正确的做法是"谁污染谁治理"。
本站文章为 宝宝巴士 SD.Team 原创,转载务必在明显处注明:(作者官方网站: 宝宝巴士 )
转载自【宝宝巴士SuperDo团队】 原文链接: /article/6669157.html
相关文章推荐
- IOS之Objective-C学习笔记(五)
- Objective-C Runtime 运行时(一):类与对象
- hibernate使用本地sql语句查询,解决List<Object[]>转换成List<实体>
- com/opensymphony/xwork2/spring/SpringObjectFactory.java:230:-1
- 是否可以修改 JavaScript 的本地对象(native object)
- a different object with the same identifier value was already associated with the session:
- 常见问题总结篇 一 、Objective C 方法和 C方法的混合调用
- jmeter中vars.putObject的使用:可传递int变量
- java实现map和object互转的三种方法
- 关于ibatis 的使用 queryForObject
- Objective-C 【多个对象内存管理(野指针&内存泄漏)】
- Objective-C 【多个对象内存管理(野指针&内存泄漏)】
- Objective-C isa 指针 与 runtime 机制
- 【Objective-C】类方法与对象方法
- Qt QAxObject操作excel文件过程总结
- OpenGL帧缓存对象(FBO:Frame Buffer Object)
- Objective-C 【单个对象内存管理(野指针&内存泄露)】
- Objective-C 【单个对象内存管理(野指针&内存泄露)】
- Objective-C 【内存管理&手动内存管理 综述】
- Objective-C 【内存管理&手动内存管理 综述】