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的区别及用途 ...
随机推荐
- PHP将解析xml变为数组方法
最近想要做一个插件机制,需要用到xml,在解析xml时候需要转换为数组,特意记录一个此种解析方式 xml文件 <?xml version="1.0" encoding=&qu ...
- nc命令详解
NetCat,在网络工具中有“瑞士军刀”美誉,其有Windows和Linux的版本.因为它短小精悍(1.84版本也不过25k,旧版本或缩减版甚至更小).功能实用,被设计为一个简单.可靠的网络工具,可通 ...
- 设置UITableView背景透明/监听cell左边的删除按钮的点击事件
_tableView = [[UITableView alloc] init]; _tableView.delegate = self; _tableView.dataSource = self; _ ...
- [wordpress]wp-api-jwt-auth 尝试添加运行在多站点中 need change
Hi,Thank you this plugin,because i use this plugin on Wordpress one Network,so the request other api ...
- 【转】IT管理人才必备的十大能力
作为IT技术人员,相信没有一个人愿意永远在底层编写程序或做简单的系统维护.经过一段时间的技术和经验的积累,很多人都向往更高层的职位,但如何能成为一个专业的IT管理人才,并不是每一个人都清晰.明了. & ...
- JSCharts
JsCharts是一款轻量级的,基于js的图形报表工具,提供了线形图,柱状图,饼图,使用简单,相对其他的图表如FusionCharts来讲功能可能不是特别强大,但是对于一些要求不高的应用来讲已经够用了 ...
- jquery设置div,文本框 表单的值示例
我们将使用前一章中的三个相同的方法来设置内容: text() - 设置或返回所选元素的文本内容html() - 设置或返回所选元素的内容(包括 HTML标记)val() - 设置或返回表单字段的值 1 ...
- 7款经典炫酷的HTML5/jQuery动画应用示例及源码
jQuery是一款普遍受前端开发者欢迎的Javascript框架,但是开发者貌似更关注jQuery开发的插件,海量的jQuery插件让前端开发者非常方便.HTML5的加入让jQuery这个家族更加丰富 ...
- 16款最佳HTML5超酷动画演示及源码
1.HTML5/CSS3图片选择动画 可选择多张图片 之前我们已经分享过几款很酷的HTML5图片特效,像HTML5 3D图片折叠特效.HTML5 3D旋转图片相册等应用.今天我们来分享一款既炫酷又实用 ...
- java web 实现验证码
验证码的作用:通常的登录或者注册系统时,都会要求用户输入验证码,以此区别用户行为和计算机程序行为,目的是有人防止恶意注册.暴力破解密码等. 实现验证码的思路:用 server 实现随机生成数字和字母组 ...