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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top