UI3_UIViewController生命周期
//
// SecondViewController.h
// UI3_UIViewController生命周期
//
// Created by zhangxueming on 15/7/2.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface SecondViewController : UIViewController @end //
// SecondViewController.m
// UI3_UIViewController生命周期
//
// Created by zhangxueming on 15/7/2.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SecondViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(50, 400, self.view.frame.size.width-100, 50);
btn.backgroundColor = [UIColor whiteColor]; [btn setTitle:@"视图模式跳转-First" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; self.view.backgroundColor = [UIColor cyanColor];
} - (void)btnClicked
{
if ([self.view superview]) {
NSLog(@"123");
[self.view superview].backgroundColor=[UIColor redColor]; [self.view removeFromSuperview];
}
//使消失当前视图控制器视图
//[self dismissViewControllerAnimated:YES completion:nil];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// ViewController.m
// UI3_UIViewController生命周期
//
// Created by zhangxueming on 15/7/2.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "SecondViewController.h" @interface ViewController () @end @implementation ViewController
//视图控制器 //当一个视图控制器被创建,并在屏幕上显示的时候。 代码的执行顺序
//1、 alloc 创建对象,分配空间
//2、init (initWithNibName) 初始化对象,初始化数据
//3、loadView 从nib载入视图 ,通常这一步不需要去干涉。除非你没有使用xib文件创建视图
//4、viewDidLoad 载入完成,可以进行自定义数据以及动态创建其他控件
//5、viewWillAppear 视图将出现在屏幕之前,马上这个视图就会被展现在屏幕上了
//6、viewDidAppear 视图已在屏幕上渲染完成
//当一个视图被移除屏幕并且销毁的时候的执行顺序,这个顺序差不多和上面的相反
//1、viewWillDisappear 视图将被从屏幕上移除之前执行
//2、viewDidDisappear 视图已经被从屏幕上移除,用户看不到这个视图了
//3、dealloc 视图被销毁,此处需要对你在init和viewDidLoad中创建的对象进行释放 - (void)loadView
{
[super loadView];
NSLog(@"开始加载视图");
} - (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"视图加载完成");
// Do any additional setup after loading the view, typically from a nib.
//UIViewController UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(50, 100, self.view.frame.size.width-100, 50);
btn.backgroundColor = [UIColor whiteColor]; [btn setTitle:@"视图模式跳转-Second" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; self.view.backgroundColor= [UIColor redColor];
} - (void)btnClicked
{
SecondViewController *svc = [[SecondViewController alloc] init]; //设置跳转模式
//UIModalTransitionStylePartialCurl 翻页效果
svc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//显示视图控制器中的view [self presentViewController:svc animated:YES completion:nil];
} //视图将要显示
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"Appering 视图将要显示");
} //视图已经显示
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"Appeared 视图已经显示");
} //视图将要消失
- (void)viewWillDisappear:(BOOL)animated
{
NSLog(@"Disappearing 视图将要消失");
}
//视图已经消失
- (void)viewDidDisappear:(BOOL)animated
{
NSLog(@"Disappeared 视图消失");
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UI3_UIViewController生命周期的更多相关文章
- react组件的生命周期
写在前面: 阅读了多遍文章之后,自己总结了一个.一遍加强记忆,和日后回顾. 一.实例化(初始化) var Button = React.createClass({ getInitialState: f ...
- 浅谈 Fragment 生命周期
版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Fragment 文中如有纰漏,欢迎大家留言指出. Fragment 是在 Android 3.0 中 ...
- C# MVC 5 - 生命周期(应用程序生命周期&请求生命周期)
本文是根据网上的文章总结的. 1.介绍 本文讨论ASP.Net MVC框架MVC的请求生命周期. MVC有两个生命周期,一为应用程序生命周期,二为请求生命周期. 2.应用程序生命周期 应用程序生命周期 ...
- UIViewController生命周期-完整版
一.UIViewController 的生命周期 下面带 (NSObject)的方法是NSObject提供的方法.其他的都是UIViewController 提供的方法. load (NSObje ...
- angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
- Spring中Bean的作用域、生命周期
Bean的作用域.生命周期 Bean的作用域 Spring 3中为Bean定义了5中作用域,分别为singleton(单例).protot ...
- Autofac - 生命周期
实例生命周期决定在同一个服务的每个请求的实例是如何共享的. 当请求一个服务的时候,Autofac会返回一个单例 (single instance作用域), 一个新的对象 (per lifetime作用 ...
- 【微信小程序开发•系列文章六】生命周期和路由
这篇文章理论的知识比较多一些,都是个人观点,描述有失妥当的地方希望读者指出. [微信小程序开发•系列文章一]入门 [微信小程序开发•系列文章二]视图层 [微信小程序开发•系列文章三]数据层 [微信小程 ...
- Xamarin.Android活动的生命周期
一.前言 用过Android手机的人一定会发现一种现象,当你把一个应用置于后台后,一段时间之后在打开就会发现应用重新打开了,但是之前的相关的数据却没有丢失.可以看出app的“生命”是掌握在系统手上的, ...
随机推荐
- linux下登入mysql和加压zip文件
1.类似于window中cmd登入一样 : mysql -u root -p ----> 回车 ---> 输入密码 就可以了 2. unzip abc.zip 直接进行解压 ...
- Delphi开发OCX详细步骤总结
首先要弄明白你要写的OCX是用在客户端还是用在服务器端 假如用在客户端: 1.创建 打开delphi 7,选择菜单"new"->"other"- ...
- android手机打电话代码分析
智能手机的打电话功能是由RIL部分来实现的,见下图: 开始分析Android源代码中的RIL部分. 又上图,以及其他相关资料,我得知在Android中有一个叫rild的守护进程.我猜测此进程与电话的拨 ...
- [Angular2 Router] Use Params from Angular 2 Routes Inside of Components
Angular 2’s ActivatedRoute allows you to get the details of the current route into your components. ...
- windows和linux中检查端口是否被占用
一.windows 1.查询端口占用情况 cmd > netstat -ano 2.查询8080端口是否被占用 cmd > netstat -ano|findstr 8080 3.查询哪个 ...
- 关于h5手机端上拉加载和下拉刷新效果-1
1.手机端目前很火的效果,上拉加载,和下拉刷新.目前主要使用 iscroll 框架来实现.先推荐一个iscroll中文学习的网站,不要感谢,我是雷锋. 2.https://iiunknown.gitb ...
- 结合源码看nginx-1.4.0之nginx多进程机制详解
目录 0. 摘要 1. nginx多进程设计思想 2. nginx多进程设计数据结构 3. nginx进程间通信机制 4. 一个简单的多进程例子 5. 小结 6. 参考源码
- 依赖注入容器Autofac的详解
Autofac和其他容器的不同之处是它和C#语言的结合非常紧密,在使用过程中对你的应用的侵入性几乎为零,更容易与第三方的组件集成,并且开源,Autofac的主要特性如下: 1,灵活的组件实例化:Aut ...
- 【Python千问 2】Python核心编程(第二版)-- 欢迎来到Python世界
1.1 什么是Python 继承了传统编译语言的强大性和通用性,同时也借鉴了简单脚本和解释语言的易用性. 1.2 起源 来源于某个项目,那些程序员利用手边现有的工具辛苦工作着,他们设想并开发了更好的解 ...
- Android小项目之九 两种上下文的区别
------- 源自梦想.永远是你IT事业的好友.只是勇敢地说出我学到! ---------- 按惯例,写在前面的:可能在学习Android的过程中,大家会和我一样,学习过大量的基础知识,很多的知识点 ...