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的“生命”是掌握在系统手上的, ...
随机推荐
- Properties 转换成Map
转自:http://feitianbenyue.iteye.com/blog/1759259 对于Properties 转换成Map 的问题: 第一时间想到的肯定有以下: 1. 迭代出来 再 pu ...
- xy
用C#實現Blob數據類型 PowerBuilder提供了Blob數據類型, 用來處理二進制數據(如:圖像,文件,二進制流,文本等等). 本質上, Blob是可變長的字節數組, 它提供了一系列全局函數 ...
- 信号之sigaction函数
sigaction函数的功能是检查或修改与指定信号相关联的处理动作(或同时执行这两种操作). #include <signal.h> int sigaction( int signo, c ...
- 代码片段------find批量处理
应用案例: 当前目录下有若干目录,有多个目录下有一个名叫build.sh的脚本,但是没有可执行权限,现在要将所有的build.sh假如可执行权限. pengdl@debian:~/work/SDK_3 ...
- 关于MFC库和CRT库冲突的分析
当MFC库和CRT库冲突时,会出现一个LNK2005的错误.具体的错误如下: nafxcwd.lib(dllmodul.obj): error LNK2005: _DllMain@12 already ...
- Balanced Lineup 倍增思想到ST表RMQ
Balanced Lineup Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 36864 Accepted: 172 ...
- oc中的block使用心得
typedef void (^ simpleBlock) (void); typedef double (^multiplyTwoValues)(double, double); typedef vo ...
- [Java] Web开发HTTP状态码整理
HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码.它由 RFC 2616 规范定义的,并得到RFC 2518.RFC 2817.RFC 2295.R ...
- 【AsyncTask整理 1】 AsyncTask几点要注意的地方
问题1:AsyncTask是多线程吗? 答:是. 问题2:AsyncTask与Handler相比,谁更轻量级? 答:通过看源码,发现AsyncTask实际上就是一个线程池,而网上的说法是AsyncTa ...
- RandomAccessFile的使用
package com.lk.C; import java.io.IOException; import java.io.RandomAccessFile; public class RandomAc ...