如何在标签栏管理的视图控制器之间共享数据 [英] How to share data between view controllers managed by tab bar

查看:11
本文介绍了如何在标签栏管理的视图控制器之间共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个由标签栏控制器管理的视图,我希望在这三个视图之间共享数据(我有一个单独的登录屏幕,可以将数据传递给第一个视图,但我的第二个视图需要利用其中的一些数据).在不同视图之间共享数据的最佳方式是什么?

I have three views managed by tab bar controller and I would like to have shared data between the three (I have a separate login screen that passes data to the first view but my second view needs to utilize some of that data). What is the best way to share data between the different views?

推荐答案

你的问题太笼统了.有很多方法可以解决这个问题,而如何解决取决于您要实现的目标.例如,您可以创建一个对象来保存这些数据并将其设置为每个控制器上的一个属性.您还可以使用 NSNotifications 让控制器知道系统事件并将相关数据放入 userInfo 字典中.其他设计涉及使用单例或委托.

Your question is too general. There are many ways to solve this problem and how you do it depends on what you are trying to achieve. For example, you might create an object to hold this data and set it as a property on each controller. You also might use NSNotifications to let controllers know of a system event and place relevant data in the userInfo dictionary. Other designs involve the use of Singletons or delegates.

因此,您需要真正清楚自己想要什么,编写代码,如果/当您遇到问题时,请返回给我们.或者,如果您有更多关于设计的问题,您可能需要考虑在 Programmers 上发帖.

So you need to really get a clear idea of what you want, code that up and if/when you have a problem with it, come back to us them. Alternatively if you questions are more about design, you might want to consider posting on Programmers.

这篇关于如何在标签栏管理的视图控制器之间共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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