iPhone开发和使用单独的模型文件?

发布于 2024-10-18 09:59:14 字数 618 浏览 1 评论 0原文

当我不断学习 iPhone / IOS 开发时,我阅读了很多有关 MVC 的内容。然而,在到目前为止我看到的各种示例文件中,我并没有真正看到模型、视图和视图的单独类。控制器?

我应该如何具体了解 MVC 在最佳实践开发的 iPhone 应用程序中的实际应用?例如,也许一个基于导航控制器和导航控制器的控制器。例如

  • 是否应该有一个单独的模型、视图和视图?每个“iPhone UI 控制器”的控制器 - 从我所看到的情况来看,iPhone 开发中似乎有 1 页 == 1 UI 控制器,那么我的问题是每个 UI 控制器是否应该拥有自己的视图文件和模型文件?

  • 鉴于 Interface Builder 和 NIB 是事物的重要组成部分,NIB 在多大程度上被视为 MVC 模式的一部分?例如,NIB 的创建是否有效地实现了“控制器”和“视图”,让您为模型创建一个单独的类(在单独的文件中)?

  • 当您获得由多个应用程序页面(例如列表视图、编辑视图等)共享/使用的共享数据(或共享模型 - 例如项目列表)时会发生什么 - 在这种情况下,这在我看来您将拥有 1 个模型,但随后在不同的页面(即视图和控制器)中重用此模型实例。

希望这是有道理的......

I've read a lot about MVC as I'm ramping up with iPhone / IOS development. However in the various sample files I've see so far I'm not really seeing separate classes for model, view & controller?

How should I concretely see MVC in action with a best practice developed iPhone application? For example perhaps one based on a NavigationController & some Table Views etc.

For example:

  • Should there be a separate Model, View & Controller for each "iPhone UI controller" - noting that there seems to be 1 page == 1 UI controller in iPhone development from what I'm seeing, then my question is effectively should each UI Controller have it's own View file and Model file?

  • Given that Interface Builder and NIBs are a big part of things, to what extent is a NIB considered to be part of the MVC pattern? e.g. does the creation of a NIB effectively implement the "controller" and the "view", leaving you to create a separate class (in a separate file) for the model?

  • What happens when you've got shared data (or a shared model - e.g. a list of items) that is shared/used by multiple application pages (e.g. list view, edit view etc) - in this case this seems to me you would have 1 x model, but then reuse this model instance across the separate pages (which are View & Controller).

Hope this makes sense...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰雪之触 2024-10-25 09:59:14

您将通过使用对象和工具的典型用途来遵循 MVC。 UIView 对象用于呈现数据和接收输入(View)。 UIViewController 响应事件并在数据模型和 UIView 层次结构(控制器)之间来回路由数据。您的数据模型位于您想要的任何位置,有时与 UIViewController 子类组合在一起,有时作为单例类(模型)出现在应用程序中。当您将共享数据模型指定为单例类时,任何需要它的类都可以从应用程序中的任何位置访问它。通过维持这种分工,您的应用程序将趋于组织良好和模块化,并且您可以维护/扩展一个方面,而无需重写程序的所有其他方面。

界面生成器是一种用于直观地构建应用程序的视图层次结构(以及某种程度上的控件层次结构)的工具。

You'll be following MVC by using the objects and tools in their typical use. A UIView object is used to present data and receive input (View). A UIViewController responds to events and routes the data back and forth between the data model and the UIView hierarchy (Controller). Your data model lives wherever you want it to, sometimes composited together with your UIViewController subclass, sometimes present in the app as a singleton class (Model). When you specify your shared data model as a singleton class then any class that needs it can access it from anywhere in the app. By maintaining this division of labor, your application will tend to be well-organized and modular, and you can maintain/extend one aspect without having to rewrite all the other aspects of the program.

Interface builder is a tool for visually building the view hierarchy (and to some extent the control hierarchy) of your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文