返回时如何将数据从一个View Controller传递到Storyboard中的另一个? [英] How to pass data from one View Controller to another in a Storyboard when going back?

查看:72
本文介绍了返回时如何将数据从一个View Controller传递到Storyboard中的另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:


  • 将UINavigationController作为初始控制器的故事板。

  • MainVC(导航控制器的root) vc)需要用户在地图上选择一个位置。

  • MainVC推送包含MapKit地图的VC并将其自身添加为MapVC在用户选择位置时发出的通知的侦听器。

  • MapKit是一个记忆猪,我们都知道。 iOS给了我一个内存警告,我做了所有需要完成的事情,然后iOS解除分配所有可以解除分配的东西,包括MainVC。

  • MapVC发出通知但是没有人去听这个。用户选择的位置丢失了,就像雨中的泪水一样。

  • 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.

鉴于此,什么是在去的时候传递位置数据的可靠方法回到MainVC?我甚至想把它写到〜/ tmp(这是我在处理图像等大量数据时要做的事情),但这似乎是浪费机器。是不是有一种我可以挂钩的机制,就像导航控制器返回上一个VC时触发的事件一样?比如,可以访问类似prepareForSegue的东西:但是相反的方向会很好。

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.

编辑我尝试去代表团但是看起来似乎我的代表仍然被释放。难道我不得不写到〜/ tmp?

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

这篇关于返回时如何将数据从一个View Controller传递到Storyboard中的另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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