获得popViewController的通知 [英] Get Notified of popViewController

查看:184
本文介绍了获得popViewController的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过使用UINavigationController创建的后退按钮弹出viewController时调用我已经拥有的方法来保存数据。

I need to save my data by calling a method I already have when a viewController is popped using the back button created by the UINavigationController.

有没有办法获取委托回调或通知我没有在文档中看到任何内容?

Is there a way to get a delegate callback or a notification I didn't see anything in the documentation?

推荐答案

您将收到通知您将看到该视图使用视图控制器方法viewWillDisappear:正在消失,但是,每次将视图移到屏幕外时都会调用此方法,无论是弹出控制器还是按下新控制器,或者其他任何可能导致视图消失的情况。

You will be notified that the view will be disappearing, with the view controller method viewWillDisappear:, however, this will be called each time the view is moved offscreen, whether that means the controller is popped or a new controller is pushed, or whatever else may cause your view to disappear.

也许更好的设计是在控制器dealloc方法中保存数据。通常,导航控制器是推入其堆栈的视图的所有者,因此弹出它通常会导致其解除分配。但情况并非总是这样,取决于您编写应用程序的方式。

Perhaps a better design would be to save your data in your controllers dealloc method. Normally, a navigation controller is the owner of a view pushed into it's stack, so popping it usually causes it to deallocate. This isn't always the case though and depends on how you've written your app.

这篇关于获得popViewController的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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