[Objective-C] 019_UIVIewController
UIViewController是iOS程序中的一个重要组成部分,对应MVC设计模式的C,它管理着程序中的众多视图,何时加载视图,视图何时消,界面的旋转等。
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团队】 原文链接: http://www.cnblogs.com/superdo/p/4771718.html
[Objective-C] 019_UIVIewController的更多相关文章
- Automake
Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...
- Objective C中的ARC的修饰符的使用---- 学习笔记九
#import <Foundation/Foundation.h> @interface Test : NSObject /** * 默认的就是__strong,这里只是做示范,实际使用时 ...
- Objective的字符串拼接 似乎没有Swift方便,但也可以制做一些较为方便的写法
NSString *str1 = @"字符串1"; NSString *str2 = @"字符串2"; //在同样条件下,Objective的字符串拼接 往往只 ...
- [转] 从 C 到 Objective C 入门1
转自: http://blog.liuhongwei.cn/iphone/objective-c/ 进军iPhone开发,最大的难点之一就是怪异的Objective C语法了.不过,了解之后才发现,原 ...
- Objective C运行时(runtime)
#import <objc/runtime.h> void setBeingRemoved(id __self, SEL _cmd) { NSLog(@"------------ ...
- Objective C ARC 使用及原理
手把手教你ARC ,里面介绍了ARC的一些特性, 还有将非ARC工程转换成ARC工程的方法 ARC 苹果官方文档 下面用我自己的话介绍一下ARC,并将看文档过程中的疑问和答案写下来.下面有些是翻译,但 ...
- Objective -C学习笔记之字典
//字典:(关键字 值) // NSArray *array = [NSArray array];//空数组 // NSDictionary *dictionary = [NSDictionary d ...
- 刨根问底Objective-C Runtime
http://chun.tips/blog/2014/11/05/bao-gen-wen-di-objective%5Bnil%5Dc-runtime-(2)%5Bnil%5D-object-and- ...
- Objective-C( Foundation框架 一 字符串)
Objective-C 中核心处理字符串的类是 NSString 与 NSMutableString ,这两个类最大的区别就是NSString 创建赋值以后该字符串的内容与长度不能在动态的更改,除非重 ...
- Objective C类方法load和initialize的区别
Objective C类方法load和initialize的区别 过去两个星期里,为了完成一个工作,接触到了NSObject中非常特别的两个类方法(Class Method).它们的特别之处,在于 ...
随机推荐
- postman(断言)
一.断言 1.Code is 200 断言状态码是200 2.contains string 断言respoonse body中包含string 3.json value check (检查JSON值 ...
- 最长递增子序列(Longest increasing subsequence)
问题定义: 给定一个长度为N的数组A,找出一个最长的单调递增子序列(不要求连续). 这道题共3种解法. 1. 动态规划 动态规划的核心是状态的定义和状态转移方程.定义lis(i),表示前i个数中以A[ ...
- springboot中json转换LocalDateTime失败的bug解决过程
环境:jdk1.8.maven.springboot 问题:前端通过json传了一个日期:date:2019-03-01(我限制不了前端开发给到后端的日期为固定格式,有些人就是这么不配合), ...
- Codeforces Round #577 (Div. 2) D. Treasure Hunting
Codeforces Round #577 (Div. 2) D. Treasure Hunting 这个一场div2 前面三题特别简单,这个D题的dp还是比较难的,不过题目告诉你了只能往上走,所以 ...
- JDBC13 ORM02 Map封装
用Map封装一条信息 conn=Utils.getConn(); ps=conn.prepareStatement("select Empname,birthday,salary from ...
- CentOS7.2 安装 MongoDB 3.4
服务器版本 CentOS7.2 MongoDB版本 3.4 1/ 下载所需资源 阿里镜像地址 http://mirrors.aliyun.com/mongodb/yum/redhat/7/mongod ...
- 基于 abp vNext 和 .NET Core 开发博客项目 - 完善与美化,Swagger登场
上一篇文章(https://www.cnblogs.com/meowv/p/12896898.html)已经成功将博客项目跑起来了,那么本篇主要是将之前遗留的问题解决,现在的代码看起来可能还是比较混乱 ...
- 如何搭建一个WEB服务器项目(二)—— 对数据库表进行基本的增删改查操作
使用HibernateTemplate进行增删改查操作 观前提示:本系列文章有关服务器以及后端程序这些概念,我写的全是自己的理解,并不一定正确,希望不要误人子弟.欢迎各位大佬来评论区提出问题或者是指出 ...
- ORACLE 统计文件后缀SQL
ORACLE 统计文件后缀SQL查询语句 select lower(substr(file_name,instr(file_name, '.', -1),length(file_name))),cou ...
- 如何在本地调试你的 Spark Job
生产环境的 Spark Job 都是跑在集群上的,毕竟 Spark 为大数据而生,海量的数据处理必须依靠集群.但是在开发Spark的的时候,不可避免我们要在本地进行一些开发和测试工作,所以如何在本地用 ...