问题
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