如何在iPhone上显示和计算数据库中的数字?

如何在iPhone上显示和计算数据库中的数字?

问题描述:

我是一个新的设计应用程序,并有一个基本的Ob-C的了解和一切如何工作。我想做的是有两个选项卡,一个是主屏幕,显示在第二个选项卡上输入的数字和百分比。用户将能够存储该信息并返回并更新它。什么是完成数学从数据库到主屏幕的最好的方法?任何教程,建议是伟大的!

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 numbers and percentages that are entered on the second tab. The user will be able to store that information and refer back to it and update it. What is the best way to complete that math from the database to the "home screen"? Any tutorials, advice is great!

谢谢。

问题通常通过使用模型 - 视图 - 控制器模式解决。在这种情况下,您的模型将是存储数字的对象,并且还使用这些数字进行计算。这里的视图将是每个选项卡中的视图 - 第一个选项卡可视化计算,第二个选项卡可视化数字。 控制器这里将是您现有的 UIViewController 对象(或其子类) - 在第一个选项卡中,响应数据模型中的更改和更新(说) code> UILabels 相应地,在第二个选项卡中,更改数据模型中的数字,例如,当用户修改 UISlider 或在 UITextView 中。

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.

创建此数据模型对象code> NSObject ),在视图控制器中将其添加为接口成员/属性,并在应用启动时将它传递给两个视图控制器。更新数据模型非常简单,只需使用第二个视图控制器调用方法和/或更改数据模型中与其使用的各种值相关的属性。

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.

您完成实现这种模式与观察部分。在这里,您可以让您的视图控制器使用 Key-值观察(可能最简单)来观察数据模型中的数据成员,或者您可以让数据模型发出 NSNotifications ,您的视图控制器将注册接收(可能更难) 。

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