首页 > 其他分享 >UIViewController生命周期方法viewDidLoad、viewWillAppear和viewDidAppear

UIViewController生命周期方法viewDidLoad、viewWillAppear和viewDidAppear

时间:2023-06-13 22:34:56浏览次数:33  
标签:调用 viewWillAppear 视图 viewDidLoad viewDidAppear 加载 view


UIViewController生命周期方法viewDidLoad、viewWillAppear和viewDidAppear

 

这3个方法执行顺序为:viewDidLoad-》viewWillAppear-》viewDidAppear

 

 viewDidLoad

Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
在视图加载后被调用,如果是在代码中创建的视图加载器,他将会在loadView方法后被调用,如果是从nib视图页面输出,他将会在视图设置好后后被调用。

 

viewWillAppear

Called when the view is about to made visible. Default does nothing
视图即将可见时调用。默认情况下不执行任何操作

更新准备显示的视图的信息。调用时,视图可能还没有被加载。

 

viewDidAppear

Called when the view has been fully transitioned onto the screen. Default does nothing
视图已完全过渡到屏幕上时调用

来触发视图完全显示在屏幕上之后的行为,例如任何动画。

viewDidLoad是当程序第一次加载view时调用,以后都不会用到,而viewDidAppear是每当切换到view时就调用。

 

备注:

(1)按下Home键之后不会调用viewWillDisappear和viewDidDisappear
因为在ios4后引入了后台的概念,当按下Home键之后,程序被挂起了,但是该View依然是原来的View,并不是新的。所以只有内存不够的时候或程序被终止的时候,才会调用viewWillDisappear和viewDidDisappear。

标签:调用,viewWillAppear,视图,viewDidLoad,viewDidAppear,加载,view
From: https://blog.51cto.com/u_16160131/6473906

相关文章

  • 关于self.view.window与viewDidLoad、viewWillAppear、viewDidAppear
    关于self.view.window与viewDidLoad、viewWillAppear、viewDidAppear 在进入一个界面(UIViewController),如果要在进入的时候使用self.view.window,那么必须在将使用代码放在viewDidAppear方法中,而viewDidLoad、viewWillAppear中self.view.window.frame为0{{0,0},{0,0}}。 -(void)......