[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 ...
随机推荐
- Android开发之TextView实现跑马灯效果
TextView及其子类,当字符内容太长显示不下时可以省略号代替未显示的字符:省略号可以在显示区域的起始,中间,结束位置,或者以跑马灯的方式显示文字(textview的状态为被选中). 其实现只需在x ...
- [HDOJ4022]Bombing(离散化+stl)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4022 一个图上有n个点,之后m个操作,每次操作一行或者一列.使得这一行或者这一列的点全部消除.每次操作 ...
- windows2003 iis6.0站点打不开,找不到服务器或 DNS 错误。
最近服务器经常出现打不开网站的现象,有时出现在上午,有时出现在中午,几乎天天都会出现一次,出现问题时,无论是回收程序池还是重启IIS或者关闭其它一些可能有影响的服务,都不能解决问题.网站打不开时,有如 ...
- HDU 1677
Nested Dolls Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- BZOJ_1629_[Usaco2007_Demo]_Cow_Acrobats_(贪心)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1629 \(n\)头牛叠罗汉.第\(i\)头牛的力量为\(s_i\),重量为\(w_i\),危险 ...
- 封装Log工具类
public class LogUtil { public static final int VERBOSE = 1; public static final int DEBUG = 2; publi ...
- 使用讯飞SDK,实现文字在线合成语音
private SpeechSynthesizer mTts; private int isSpeaking = 0; mTts= SpeechSynthesizer.createSynthesize ...
- 笨笨-歌词伴侣V1.2(酷狗KRC转LRC,LRC歌词批量下载)
最近由于某些热心博友在我CSDN博客上使用了我的软件,提出了一些建议,看到自己的成果有人使用并且提出了一些建议,焉有不高兴之理!刚好碰上最近研究UI界面,有了一个初步的框架,就顺手将歌词相关功能集 ...
- Android PRODUCT_COPY_FILES 自动拷贝文件
/********************************************************************** * Android PRODUCT_COPY_FILES ...
- OK335xS psplash Screen 移植
/*********************************************************************** * OK335xS psplash Screen 移植 ...