How to share data between view controllers managed by tab bar

假如想象 提交于 2019-12-11 10:30:15

问题


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?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/21655938/how-to-share-data-between-view-controllers-managed-by-tab-bar

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