Your problem is typically solved by using the Model-View-Controller pattern. In this case, your "model" will be an object that stores the numbers and also does the computations with those numbers. Your "view" here will be the views in each tab -- the first tab visualizing the computations, the second tab visualizing the numbers. The "controller" here will be your existing UIViewController
objects (or subclasses thereof) -- in the first tab, responding to changes in the data model and updating the (say) UILabels
accordingly, in the second tab, changing the numbers in the data model when the user, for example, modifies the value on a UISlider
or in a UITextView
.
Create this data model object (which should just be a subclass of NSObject
) in your application delegate, add it as a interface member/property in your view controllers, and pass it to both view controllers when the app starts up. Updating the data model is as simple as having the second view controller call methods and/or change properties in the data model related to various values it uses.
You complete the implementation of this pattern with the observation part. Here, you can either have your view controllers use Key-Value Observing (might be simplest) to watch data members in the data model, or you can have the data model emit NSNotifications
which your view controller would then register to receive (might be harder).