IOS 控件的生命周期
ViewController的生命周期包括:
Initialize
ViewDidLoad
ViewWillAppear
ViewDidAppear
ViewWillDisappear
ViewDidDisappear
ViewDidUnload
Dispose
对于Application来说,ViewController的每个阶段都对应了一个方法,IOS会在适当的时间调用对应的方法,因此,我们可以在每个方法中添加对应的代码来做我们想做的事。需要注意的是,这些方法都是为ViewController服务的,对于Views对象来说,是没有这些方法的。
View的生命周期方法如下:
* ViewDidLoad - Called when you create the class and load from xib. Great for initial setup and one-time-only work
* ViewWillAppear - Called right before your view appears, good for hiding/showing fields or any operations that you want to happen every time before the view is visible. Because you might be going back and forth between views, this will be called every time your view is about to appear on the screen
* ViewDidAppear - Called after the view appears - great place to start an animations or the loading of external data from an API.
* ViewWill/DidDisappear - Same idea as the WillAppear.
* ViewDidUnload/Dispose - Available to you, In objective-c, this is where you do your cleanup and release of stuff, but this is handled automatically so not much you really need to do here.
Application的生命周期包括:
在IOS中,生命周期就是由一系列的方法构成, 对于一个App来说,涉及到的生命周期有:
1、点击icon启动,对应的方法有:
didFinishLaunchingWithOptions:
applicationDidBecomeActive:
2、按下Home键,返回桌面,对应方法:
applicationWillResignActive
applicationDidBecomeInactive
3、再点击icon回到前台,对应方法:
applicationWillEnterForegroud
applicationDidBecomeActive
4、Application忽然被终止,对应方法:
applicationWillTerminate
这儿需要注意,点2下home键,把后台程序关掉不会调用这个方法,在苹果的IOS开发指南上有如下描述:
”Even if you develop your application using iPhone SDK 4 and later, you must still be prepared for your application to be terminated. If memory becomes constrained, the system might remove applications from memory in order to make more room. If your application is currently suspended, the system removes your application from memory without any notice. However, if your application is currently running in the background, the system does call the applicationWillTerminate:method of the application delegate. Your application cannot request additional background execution time from this method.“ 就是说,在机器内存不足时,IOS会清理后台程序,在这个时候会调用该方法,一般情况下,很少会用到这个方法,尽量不要在这个方法里写你的应用逻辑。
IOS 控件的生命周期的更多相关文章
- React-Native控件的生命周期
React-Native控件的生命周期
- ASp.Net控件的生命周期
服务端事件 页面生命周期 描述 Init Initialization 初始化控件树 LoadViewState Unpack ViewState 从ViewState里提取出状态信息 LoadCon ...
- asp.net服务控件的生命周期
1. 初始化 - Init事件 (OnInit 方法) 2. 加载视图状态 - LoadViewState方法 3. 处理回发数据 - LoadPostData方法 对实现 ...
- iOS学习笔记—ViewController/生命周期
ViewController是iOS应用程序中重要的部分,是应用程序数据和视图之间的重要桥梁,ViewController管理应用中的众多视图.iOS的SDK中提供很多原生ViewController ...
- iOS 应用程序的生命周期
iOS 应用程序的生命周期(网络资源总结) http://blog.csdn.net/totogo2010/article/details/8048652 http://www.cocoachina. ...
- iOS控件之UIResponder类
iOS控件之UIResponder类 在iOS中UIResponder类是专门用来响应用户的操作处理各种事件的,我们知道UIApplication.UIView.UIViewController这几个 ...
- iOS视图控制器的生命周期
今天面试有一道面试题因为回答不好,因为也不经常涉及所以有点模糊,我选择了最保守的回答,没有展开写出我对这个问题的理解. 问题:IOS 开发 loadView 和 viewDidLoad 的区别? 经过 ...
- iOS视图控制对象生命周期
iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...
- IOS 视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途
iOS视图控制对象生命周期-init.viewDidLoad.viewWillAppear.viewDidAppear.viewWillDisappear.viewDidDisappear的区别及用途 ...
随机推荐
- codeforces 579D D. "Or" Game(前后缀+贪心)
题目链接: D. "Or" Game time limit per test 2 seconds memory limit per test 256 megabytes input ...
- 查询score中选学多门课程的同学中分数为非最高分成绩的记录。
20.查询score中选学多门课程的同学中分数为非最高分成绩的记录. select * from score a where sno in ( select sno from score group ...
- Linux之cuda安装
1.下载https://developer.nvidia.com/cuda-downloads 2.双击下载好的deb进行安装 3.sudo apt-get install cuda 4.As par ...
- freemarker编辑器eclipse插件
freemarker编辑器eclipse插件 支持语法高亮,语法校验,代码提示的工具 freemarker IDE(JBoss): http://download.jboss.org/jbossto ...
- 学习Slim Framework for PHP v3 (六)--route怎么被匹配的?
先标记觉得以后会用到的内容: // add route to the request's attributes in case a middleware or handler needs access ...
- MySQL配置管理
数据库的链接: 获取项目结果集和链接: package Dao; import java.sql.Connection; import java.sql.ResultSet; import java. ...
- 2014.10.09 Andrew 学习 WPF(刘铁锰) 笔记分享
引言 主要是讲了关于WPF只是表现层的工具. 第一章: XAML : 可扩张应用程序标记语言 Extensible Application Markup Language 什么是XAML? X ...
- VMware Workstation CentOS-6.4-x86_64-minimal 配置网络以及安装JDK和tomcat
1.配置网络(能够联网)转自:http://blog.sina.com.cn/s/blog_75ad10100101ma4c.html 1)vmware的网卡连接方式选择为桥接(bridged)不要用 ...
- 建立临时的表 数据 空值 与 NULL 转换
if exists ( select * from INFORMATION_SCHEMA.tables where table_name = 'Config_Order_ChargesToPreVie ...
- 【学习笔记】【C语言】数组
1. 什么是数组 数组,从字面上看,就是一组数据的意思,没错,数组就是用来存储一组数据的 2. 数组的特点 只能存放一种类型的数据,比如int类型的数组.float类型的数组 里面存放的数据称为“元素 ...