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的区别及用途 ...
随机推荐
- 剑指Offer14 逆序链表
/************************************************************************* > File Name: 14_Revers ...
- ant 命令学习详解
ant -verbose //输出 ant编译时的详情
- Linux之apt-get无sudo权限安装软件
apt-get source package cd package ./configure --prefix=$HOME make make install
- 应用越来越广泛的css伪类
说起css伪类,学习web前端网页设计的同学们应该对此应该不是很陌生,以前很多的网页的特效大多是通过js来实现的.但是随着CSS3不断开发,利用css实现网页的特效不仅响应不错,而且还减少了很多的代码 ...
- c# 生成项目或重新生成项目时报“Project not selected to build for this solution configuration”之解决办法
菜单->生成->配置管理器->给要生成的项目打钩
- Swiper之滑块3
上章Swiper滑块2.Swiper滑块1都是手动的,这章我们来自动的! 其实只是加了Swiper的speed(滑动速度即slider自动滑动开始到结束的时间)属性而已(∩_∩),单位是ms < ...
- oracle发送邮件
1.创建发送邮件的存储过程 CREATE OR REPLACE PROCEDURE send_mail(p_recipient VARCHAR2, -- 邮件接收人 p_subject VARCHAR ...
- 20141128—JavaScript对象
JavaScript 中的所有事物都是对象:字符串.数值.数组.函数... String 对象的 length 属性来获得字符串的长度: var message="Hello World!& ...
- AMQ学习笔记 - 15. 实践方案:基于ActiveMQ的统一日志服务
概述 以ActiveMQ + Log4j + Spring的技术组合,实现基于消息队列的统一日志服务. 参考:Spring+Log4j+ActiveMQ实现远程记录日志——实战+分析 与参考文章的比较 ...
- 从0开始学习react(一)
本人前端小菜鸡一枚,因为公司要重构网站,打算用用react,毕竟一切为了学习(装B)嘛!!! 在学习react之前,看了许多资料,博客,官方文档之类的,可我这记吃不记打的记性,还是需要在这里记录一下, ...