How to pass data from one View Controller to another in a Storyboard when going back?

…衆ロ難τιáo~ 提交于 2020-01-03 05:08:11

问题


Scenario:

  • Storyboard with UINavigationController as initial controller.
  • MainVC (navigation controller's root vc) needs the user to choose a location on a map.
  • MainVC pushes a VC containing a MapKit map and adds itself as listener for a notification the MapVC sends out when the user chooses a location.
  • MapKit is a memory hog, we all know that. iOS gives me a memory warning, I do all the things that need to be done, then iOS deallocates all it can deallocate, including the MainVC.
  • MapVC sends out the notification but there's nobody to listen to it. The location the user chose is lost, like tears in rain.

Given this, what's a reliable way to pass that location data when going back to MainVC? I even thought of writing it down to ~/tmp (which is something I use to do when dealing with large amount of data like images) but that seems like a waste of machinery. Isn't there a mechanism I can hook to, like an event fired when the navigation controller goes back to the previous VC? Like, having access to something like the prepareForSegue: but on the opposite direction would be nice.

EDIT I tried going for delegation but it seems my delegate gets released nonetheless. Am I stuck with having to write to ~/tmp?


回答1:


See my answer here for a detailed explanation of setting up a delegate and delegate protocol - here



来源:https://stackoverflow.com/questions/9358381/how-to-pass-data-from-one-view-controller-to-another-in-a-storyboard-when-going

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