[iOS基础控件 - 6.11.1] - 控制器 & 控制器view
通过storyboard创建
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 }



- loadView代码(controller实现loadView方法)
- storyboard描述
- xib

最新版的官方文档:




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基础控件 - 6.11.1] - 控制器 & 控制器view的更多相关文章
- [iOS基础控件 - 6.11.3] 私人通讯录Demo 控制器的数据传递、存储
A.需求 1.搭建一个"私人通讯录"Demo 2.模拟登陆界面 账号 密码 记住密码开关 自动登陆开关 登陆按钮 3.退出注销 4.增删改查 5.恢复数据(取消修改) 这个代码 ...
- [iOS基础控件 - 6.11.2] - UINavigationController 多控制器 简单使用
A.概念 1.通常一个app有多个控制器 2.需要对这些控制器进行管理 3.有多个view的时候,用一个父view去管理多个子view 4.控制器管理也是如此,使用给一个父控制器,去控制子控制器 ...
- [iOS基础控件 - 6.11.4] storyboard 的 Segue
A.概念 storyboard中的跳转事件连线,都是一个UIStoryboardSegue对象(Segue) 来源控制器 触发控制器 目标控制器 跳转到的控制器 Seg ...
- [iOS基础控件 - 6.11.5] 沙盒 & 数据存储
A.沙盒 每个APP都有一个沙盒,是独立存在的 1.Xcode5和Xcode6的模拟器文件目录 a.模拟器路径改版 (1)Xcode5中模拟器路径为:/Users/用户名/Library/Appl ...
- [iOS基础控件 - 5.5] 代理设计模式 (基于”APP列表"练习)
A.概述 在"[iOS基础控件 - 4.4] APP列表 进一步封装,初见MVC模式”上进一步改进,给“下载”按钮加上效果.功能 1.按钮点击后,显示为“已下载”,并且不 ...
- [iOS基础控件 - 6.12.3] @property属性 strong weak copy
A.概念 @property 的修饰词 strong: 强指针/强引用(iOS6及之前是retain) weak: 弱智真/弱引用(iOS6及之前是assign) 默认情况所有指针都是强指针 ...
- [iOS基础控件 - 6.12.1] QQ菜单管理 UITabBarController 控制器管理
A.需求 1.类似QQ.微信顶部或者底部的窗口转换导航条 2.给每个页面添加相应内容 B.UITabBarController 1.基本概念: (1)内容高度 iOS7之前内容高度为:屏幕高度 - ...
- iOS 基础控件(下)
上篇介绍了UIButton.UILabel.UIImageView和UITextField,这篇就简短一点介绍UIScrollView和UIAlertView. UIScrollView 顾名思义也知 ...
- [iOS基础控件 - 6.10.2] PickerView 自定义row内容 国家选择Demo
A.需求 1.自定义一个UIView和xib,包含国家名和国旗显示 2.学习row的重用 B.实现步骤 1.准备plist文件和国旗图片 2.创建模型 // // Flag.h // Co ...
随机推荐
- iOS学习笔记:iOS核心动画中的常用类型
CATransaction 当我们在自定义的图层上修改某些支持动画的属性时,系统会为该属性的修改自动产生动画.这种其实属于隐式动画.隐式动画要得益于CATransaction. 一个CATransac ...
- 发布 windows 10 universal app 时微软账号验证失败
具体错误:Visual Studio encountered an unexpected network error and can't contact the Microsoft account s ...
- UVa 11235 (RMQ) Frequent values
范围最值问题,O(nlogn)的预处理,O(1)的查询. 这个题就是先对这些数列进行游程编码,重复的元素只记录下重复的次数. 对于所查询的[L, R]如果它完全覆盖了某些连续的重复片段,那么查询的就是 ...
- web交互方式
轮询:客户端定时向服务器发送Ajax请求,服务器接到请求后马上返回响应信息并关闭连接. 优点:后端程序编写比较容易. 缺点:请求中有大半是无用,浪费带宽和服务器资源. 实例:适于小型应用. 长轮询:客 ...
- MongoDB入门分享-笔记整理精选
最近在学习MongoDB,怕以后忘记,自己做了一个整理,给不知道的小伙伴一起分享学习一下. 第一步> 首先到官网下载,安装MongoDB.(注意MongoDB还有一个可视化管理工具叫: Mong ...
- Java [Leetcode 110]Balanced Binary Tree
题目描述: Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced b ...
- poj 2762 Going from u to v or from v to u?
题目描述:为了让他们的儿子变得更勇敢些,Jiajia和Wind将他们带到一个大洞穴中.洞穴中有n个房间,有一些单向的通道连接某些房间.每次,Wind选择两个房间x和y,要求他们的一个儿子从一个房间走到 ...
- Cocos2d提供的字体(图文并茂)
1.AppleGothic CCLabelTTF *myLabel = [CCLabelTTF labelWithString:@"AppleGothic" fontName:@& ...
- 域名下Web项目重定向出现DNS域名解析错误问题
问题: 项目使用的是阿里云的ESC,前几天为IP地址添加了域名 发现发送正常请求时跳转没问题,但发送重定向请求时,页面就会出现DNS域名解析错误的情况 1.我在Tomcat的server.xml中配置 ...
- mysql使用经验总结
在工作中难免会遇到一些这个问题那个问题,当然在mysql中也不例外.今天就让我们来学学mysql中一些比较常用的东西 . 1.有时我们想去查某张表中的字段,但是表中的数据多,字段也很多,如果用sel ...