How do I display and calculate numbers from a database on iPhone?

前端 未结 1 933
借酒劲吻你
借酒劲吻你 2020-12-20 08:25

I am new to designing apps and have a basic understand of Ob-C and how everything works. What I would like to do is have two tabs, one is a home screen that displays number

1条回答
  •  [愿得一人]
    2020-12-20 09:06

    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).

    0 讨论(0)
提交回复
热议问题