objective-c - viewWillAppear、viewDidAppear、viewWillDisappear、viewDidDisappear 指南

标签 objective-c ios uiviewcontroller viewwillappear viewdidappear

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

例如,如果我必须调用一个从 WS 检索数据的方法,我必须在哪里调用它?我在哪里可以注册/注销 NSNotification?等

最佳答案

来自 UIViewController

viewWillAppear:

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:

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.

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:

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:

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.

更多信息您可以查看View Controller Programming Guide for iOS

关于objective-c - viewWillAppear、viewDidAppear、viewWillDisappear、viewDidDisappear 指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7386333/

相关文章:

javascript - Iphone UIWebView无法处理javascript按钮

objective-c - NSDocumentController 新文档 :

iphone - 成就完成处理程序不检测何时没有可用的 Internet 连接

ios - 为什么调用 super 是此方法的最后一件事而不是第一件事?

iphone - 如何添加pull tableview up来刷新uitableview里面的数据

swift - 如何在 Playgrounds 中设置 ViewController?

ios - 点击数字的 UITextView 自定义操作

iphone - 如何将 facebook 发布/消息时间转换为正常 NSDate

iOS 9 将旋转至界面方向已弃用

iOS Swift 使用 Alamofire 上传 PDF 文件(多部分)