viewWillAppear,viewDidAppear,viewWillDisappear,viewDidDisappear的指南 [英] Guidelines for viewWillAppear, viewDidAppear, viewWillDisappear, viewDidDisappear

查看:126
本文介绍了viewWillAppear,viewDidAppear,viewWillDisappear,viewDidDisappear的指南的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有正确使用这些方法的指导原则?特别是,我想知道我可以在其中使用什么类型的代码。

Are there any guidelines for using these methods in the right manner? In particular, I would like to know what type of code I could use inside them.

例如,如果我必须调用从WS检索数据的方法,我在哪里打电话给它?我在哪里可以注册/取消注册NSNotification?等等。

For example, if I have to call a method that retrieves data from a WS, where do I have to call it? Where can I register/unregister a NSNotification? etc.

推荐答案

来自 UIViewController

viewWillAppear:

viewWillAppear:


在接收器的视图即将在屏幕上显示之前以及在配置任何动画以显示视图之前调用此方法。您可以覆盖此方法以执行与显示视图相关联的自定义任务。例如,您可以使用此方法更改状态栏的方向或样式,以与要显示的视图的方向或样式进行协调。如果重写此方法,则必须在实现中的某个时刻调用super。

This method is called before the receiver’s view is about to be displayed onscreen and before any animations are configured for showing the view. You can override this method to perform custom tasks associated with presenting the view. For example, you might use this method to change the orientation or style of the status bar to coordinate with the orientation or style of the view being presented. If you override this method, you must call super at some point in your implementation.

viewWillDisappear:

viewWillDisappear:


调用此方法以响应从其窗口中删除或由另一个视图覆盖的视图。在实际删除或覆盖视图之前以及在配置任何动画之前调用此方法。

This method is called in response to a view being removed from its window or covered by another view. This method is called before the view is actually removed or covered and before any animations are configured.

子类可以覆盖此方法并使用它来提交编辑更改,重新签名响应者的视图状态,或执行其他相关任务。例如,您可以使用此方法还原对视图首次显示时在viewDidDisappear:方法中创建的状态栏方向或样式的更改。如果重写此方法,则必须在实现中的某个时刻调用super。

Subclasses can override this method and use it to commit editing changes, resign the first responder status of the view, or perform other relevant tasks. For example, you might use this method to revert changes to the orientation or style of the status bar that were made in the viewDidDisappear: method when the view was first presented. If you override this method, you must call super at some point in your implementation.

viewDidAppear:

viewDidAppear:


您可以覆盖此方法以执行与显示视图相关的其他任务。如果重写此方法,则必须在实现中的某个时刻调用super。

You can override this method to perform additional tasks associated with presenting the view. If you override this method, you must call super at some point in your implementation.

viewDidDisappear:

viewDidDisappear:


您可以覆盖此方法以执行与解除或隐藏视图相关的其他任务。如果重写此方法,则必须在实现中的某个时刻调用super。

You can override this method to perform additional tasks associated with dismissing or hiding the view. If you override this method, you must call super at some point in your implementation.

有关详细信息,您可以检查适用于iOS的View Controller编程指南

For further information you may check View Controller Programming Guide for iOS

这篇关于viewWillAppear,viewDidAppear,viewWillDisappear,viewDidDisappear的指南的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆