Get Notified of popViewController

梦想与她 提交于 2020-01-23 03:24:05

问题


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?


回答1:


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.

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.




回答2:


In your viewWillDisappear method, you can check the property:

[self isMovingFromParentViewController]

to find out if the view is disappearing as a result of being popped off the stack or not.



来源:https://stackoverflow.com/questions/4834723/get-notified-of-popviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!