UIApplication
执行顺序:
2016-03-22 13:58:37.681 HBLifeCircleTest[2705:146296] -[AppDelegate application:didFinishLaunchingWithOptions:]
2016-03-22 13:58:37.685 HBLifeCircleTest[2705:146296] -[AppDelegate applicationDidBecomeActive:]
//点击home键
2016-03-22 14:00:06.786 HBLifeCircleTest[2705:146296] -[AppDelegate applicationWillResignActive:]
2016-03-22 14:00:07.503 HBLifeCircleTest[2705:146296] -[AppDelegate applicationDidEnterBackground:]
//点击应用
2016-03-22 14:00:11.134 HBLifeCircleTest[2705:146296] -[AppDelegate applicationWillEnterForeground:]
2016-03-22 14:00:11.647 HBLifeCircleTest[2705:146296] -[AppDelegate applicationDidBecomeActive:]
//双击home退出
2016-03-22 14:00:19.463 HBLifeCircleTest[2705:146296] -[AppDelegate applicationWillResignActive:]
2016-03-22 14:00:28.677 HBLifeCircleTest[2705:146296] -[AppDelegate applicationDidEnterBackground:]
2016-03-22 14:00:28.680 HBLifeCircleTest[2705:146296] -[AppDelegate applicationWillTerminate:]
IOS的应用程序一共有5种状态。
- Not running(未运行):程序未启动
- Inactive(未激活):其他两个状态切换时出现的短暂状态。唯一在此状态停留时间比较长的情况是:当用户锁屏时?或者系统提示用户去响应Alert窗口(如来电、信息)时
- Active(激活):在屏幕上显示的正常运行状态,该状态下可以接收用户输入并更新显示
- Backgroud(后台):程序在后台且能执行代码。用户按下Home键不久后进入此状态(先进入了Inactive状态,再进入Background状态),然后会迅速进入挂起状态(Suspended)。有的程序经过特殊的请求后可以长期处于Backgroud状态
- Suspended(挂起):程序在后台不能执行代码。普通程序在进入Background状态不久后就会进入此状态。当挂起时,程序还是停留在内存中的,当系统内存低时,系统就把挂起的程序清除掉,为前台程序提供更多的内存
状态切换图关于Active和Inactive的切换:
应用程序在前台时有2种状态:Active和Inactive。大多数情况下,Inactive状态只是其他两个状态切换时出现的短暂状态(不是任意两个状态之间的切换都会进入Inactive,见图),如打开应用,它会从Not Running先进入Inactive再进入Active;如前后台应用切换时,Inactive会在Active和Background之间短暂出现。但是也有其他情况,Active和Inactive可以在前台运行时进行切换,比如系统弹出Alert,此时应用会从Active切换到Inactive,直到用户确认再返回Actvie;再如用户拉下通知页,也会发生Active和Inactive的切换;还有来电但拒接、双击Home键但返回原应用等都不进入Background,而只是在Active和Inactive切换。
1.application:didFinishLaunchingWithOptions:
程序首次已经完成启动时执行,若直接启动,launchOptions中没有数据;否则,推送,3Dtouch等方式打开应用。launchOptions将包含对应方式的内容。
2.applicationWillResignActive(将进入后台)
程序将要失去Active状态时调用,比如按下Home键或有电话信息进来。对应applicationWillEnterForeground(将进入前台),这个方法用来
暂停正在执行的任务;
禁止计时器;
减少OpenGL ES帧率;
若为游戏应暂停游戏;
总结为一个字:停!
3.applicationDidEnterBackground(已经进入后台)
程序已经进入后台时调用,对应applicationDidBecomeActive(已经变成前台),这个方法用来
释放共享资源;
保存用户数据(写到硬盘);
作废计时器;
保存足够的程序状态以便下次恢复;
总结为4个字:释放、保存!
4.applicationWillEnterForeground(将进入前台)
程序即将进去前台时调用,对应applicationWillResignActive(将进入后台)。这个方法用来撤销applicationWillResignActive中做的改变。
5.applicationDidBecomeActive(已经进入前台)
程序已经变为Active(前台)时调用。对应applicationDidEnterBackground(已经进入后台)。若程序之前在后台,最后在此方法内刷新用户界面。
6.applicationWillTerminate
程序即将退出时调用。记得保存数据,如
其他类使用相应NotificationCenter通知来感知这些状态变化。
UIViewController
当一个视图控制器被创建,并在屏幕上显示的时候。 代码的执行顺序
1、 alloc 创建对象,分配空间
2、init (initWithNibName) 初始化对象,初始化数据
3、loadView 创建self.view
4、viewDidLoad 载入完成,可以进行自定义数据以及动态创建其他控件
5、viewWillAppear 视图将出现在屏幕之前,马上这个视图就会被展现在屏幕上了
6、viewDidAppear 视图已在屏幕上渲染完成
7、viewWillDisappear 视图将被从屏幕上移除之前执行
8、viewDidDisappear 视图已经被从屏幕上移除,用户看不到这个视图了
9、dealloc 视图被销毁,
VC1 push VC2 VC2 popTo VC1
2015-10-29 17:32:30.767 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewDidLoad]
2015-10-29 17:32:30.768 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewWillAppear:]
2015-10-29 17:32:30.801 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewDidAppear:]
2015-10-29 17:32:31.739 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewDidLoad]
2015-10-29 17:32:31.739 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewWillDisappear:]
2015-10-29 17:32:31.741 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewWillAppear:]
2015-10-29 17:32:32.247 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewDidDisappear:]
2015-10-29 17:32:32.247 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewDidAppear:]
2015-10-29 17:32:33.060 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewWillDisappear:]
2015-10-29 17:32:33.060 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewWillAppear:]
2015-10-29 17:32:33.563 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewDidDisappear:]
2015-10-29 17:32:33.564 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewDidAppear:]
2 PanGesture confirm pop
//panGesture began 触发
2015-10-29 17:41:25.917 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewWillDisappear:]
2015-10-29 17:41:25.917 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewWillAppear:]
//panGesture end 触发
2015-10-29 17:41:28.232 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewDidDisappear:]
2015-10-29 17:41:28.232 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewDidAppear:]
2 PanGesture cancel pop
//panGesture began 触发
2015-10-29 17:39:59.035 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewWillDisappear:]
2015-10-29 17:39:59.035 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewWillAppear:]
//panGesture end 触发
2015-10-29 17:40:01.382 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewWillDisappear:]
2015-10-29 17:40:01.382 HBNavigationBarDemo[14468:2081258] 111-[ViewController viewDidDisappear:]
2015-10-29 17:40:01.382 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewWillAppear:]
2015-10-29 17:40:01.382 HBNavigationBarDemo[14468:2081258] 222-[ViewController2 viewDidAppear:]
pop成功后delloc方法最后调用
model present
//1打开
2015-10-29 17:53:44.998 HBNavigationBarDemo[14825:2193035] 111-[ViewController viewDidLoad]
2015-10-29 17:53:44.999 HBNavigationBarDemo[14825:2193035] 111-[ViewController viewWillAppear:]
2015-10-29 17:53:45.045 HBNavigationBarDemo[14825:2193035] 111-[ViewController viewDidAppear:]
//点击按钮触发present VC2
2015-10-29 18:01:33.213 HBNavigationBarDemo[14961:2235069] 222-[ViewController2 viewDidLoad]
//触发操作后执行的代码
2015-10-29 18:01:33.215 HBNavigationBarDemo[14961:2235069] 111behind -[ViewController present:]
2015-10-29 18:01:33.217 HBNavigationBarDemo[14961:2235069] 111-[ViewController viewWillDisappear:]
2015-10-29 18:01:33.236 HBNavigationBarDemo[14961:2235069] 222-[ViewController2 viewWillAppear:]
2015-10-29 18:01:33.739 HBNavigationBarDemo[14961:2235069] 222-[ViewController2 viewDidAppear:]
2015-10-29 18:01:33.739 HBNavigationBarDemo[14961:2235069] 111-[ViewController viewDidDisappear:]
//complete block
2015-10-29 18:01:33.739 HBNavigationBarDemo[14961:2235069] block __26-[ViewController present:]_block_invoke
//关闭触发后的代码
2015-10-29 18:04:11.705 HBNavigationBarDemo[15028:2249677] 222behind -[ViewController2 close:]
2015-10-29 18:04:11.706 HBNavigationBarDemo[15028:2249677] 222-[ViewController2 viewWillDisappear:]
2015-10-29 18:04:11.707 HBNavigationBarDemo[15028:2249677] 111-[ViewController viewWillAppear:]
2015-10-29 18:04:12.209 HBNavigationBarDemo[15028:2249677] 111-[ViewController viewDidAppear:]
2015-10-29 18:04:12.210 HBNavigationBarDemo[15028:2249677] 222-[ViewController2 viewDidDisappear:]
//complete block
2015-10-29 18:04:12.210 HBNavigationBarDemo[15028:2249677] 222block __25-[ViewController2 close:]_block_invoke
2015-10-29 18:04:12.210 HBNavigationBarDemo[15028:2249677] 222-[ViewController2 dealloc]
UIScrollView代理方法
//只要滑动,就改变了contentOffset,就会调用此方法
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
// 手指放在content上准备拖动
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView;
//手指将要离开
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
//手指已经离开
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate;
//由于惯性还要再滑动
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
//惯性结束,停止滑动
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
UITableView代理方法
第一轮:
每次reloadData都会有以下的循环
1、numberOfSectionsInTableView :此代理方法只执行一次,假如section=0,下面函数不执行,默认为1
2、heightForHeaderInSection ,执行section个数的次数,
3、heightForFooterInSection ,同上
4、numberOfRowsInSection ,执行section个数的次数
8、heightForRowAtIndexPath ,行高,先执行section=0,对应的row次数
9、cellForRowAtIndexPath
10、willDisplayCell
NSObject
load方法:一个类被加载到runtime的时候调用
initialize:调用方法前最先执行的。线程安全的
网友评论