So, basically, I have four different views that are switched via a tab bar at the bottom of the screen. I have a view controller set up for each one, and they all work fine. The only problem is that I have no idea how to share information between the different views-for example, I have an IBAction on one that takes the output of a UISegmentedControl and stores the selection as an integer (1,2,3,4). The problem is, I don’t know how to access that integer from the first view controller (the one that actually does stuff with that information). I’m sure this is a very basic problem but my google-fu doesn’t seem to be working here. Thanks!
Share
Using the MVC method, information should not be stored in the view controllers. You should have a separate object which stores the information, the view controllers load it, and the views display it. The easiest way to do this would be to store the information in your application’s delegate. Then, whenever the view controller needs to find/change some information, it can use
[[UIApplication sharedApplication] delegate]to get the delegate, and load/change the information as needed. Load the information to update the display in viewDidLoad or viewWillDisplay:, and change it in action methods.Edit Example:
DelegateClass.h
DelegateClass.m
MyViewController.m