加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

-viewWillAppear:和 -viewDidAppear:区别

发布时间:2020-12-17 00:43:07 所属栏目:安全 来源:网络整理
导读:?-viewWillAppear:和 -viewDidAppear:区别在于will和did的区别! viewWillAppear是在视图出现之前调用,更新用于显示视图的信息,此时视图还没有appear。 viewDidAppear是在视图出现之后调用,用于更新视图显示出来后,一些动画之类的操作。 1)? ViewDidLoad

?-viewWillAppear:和 -viewDidAppear:区别在于will和did的区别!

viewWillAppear是在视图出现之前调用,更新用于显示视图的信息,此时视图还没有appear。

viewDidAppear是在视图出现之后调用,用于更新视图显示出来后,一些动画之类的操作。

1)?ViewDidLoad?- Whenever I'm adding controls to a view that should appear together with the view,right away,I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example,if my view is a form with 3 labels,I would add the labels here; the view will never exist without those forms.

2)?ViewWillAppear: I use ViewWillAppear usually just to update the data on the form. So,for the example above,I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive,and you should avoid as much as possible doing that on the ViewWillAppear method,becuase when this gets called,it means that the iPhone is already ready to show the UIView to the user,and anything heavy you do here will impact performance in a very visible manner (like animations being delayed,etc).If you override this method,you must call super at some point in your implementation.

3)?ViewDidAppear: Finally,I use the ViewDidAppear to start off new threads to things that would take a long time to execute,like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user,you can show a nice "Waiting" message to the user while you get the data.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读