组织iOS项目的MVC设计模式 [英] Organizing iOS project for MVC design pattern

查看:128
本文介绍了组织iOS项目的MVC设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iPhone的多视图应用程序,目前有我的意见(VIEW)设置和他们的过渡(CONTROLLER?)工作很好。现在我想为实际的程序数据(MODEL)添加对象。



我的问题是:坚持Model View Controller(MVC)设计模式?我知道我应该创建单独的类来实现我的数据结构,我的控制器类可以传递消息给他们从视图,但有任何其他组织的考虑,我应该检查?



其他细节:播放预先录制的,也许是用户生成的音频是必不可少的。我知道这些是模型元素,但它们如何与V和C有关我仍然有点模糊。我想,当用户动作需要音频播放时,CONTROLLER应该传递一个消息到MODEL准备好适当的声音,但在什么地方应该调整的播放生活?在一个独立于ViewController的PlayerController中,我想象一下?



非常感谢和赞许我的MVC noobery。

解决方案

Caleb给出了一个很好的介绍和概述如何思考问题。在您的特定情况下,以下是您可能已经提供您的描述的一些作品:




  • Clip用于保持实际音频数据。


  • 玩家(V) - 实际上播放剪辑在扬声器上。是的,这是一种在MVC中的查看。音频只是另一种演示。也就是说,你永远不会称之为PlayerView,因为这将表明它是UIView的子类。


  • PlayerView(V)玩家。 ClipManager(C) - 一个对象,它将跟踪系统中的所有剪辑,并管理从网络中提取它们,添加


  • PlayerViewController(C) - 从ClipManager中检索剪辑,并协调Player和PlayerView以显示和播放,以及任何其他UI元素(例如后退按钮等)。




一个例子你如何可能打破了一些理论音频播放器应用程序。有很多正确的MVC方法来做到这一点,但这是一种想法。


I'm working on a multiview app for iPhone and currently have my views (VIEW) set up and their transitions (CONTROLLER?) working nicely. Now I'd like to add objects for the actual program data (MODEL).

My question is: How should I structure my data to adhere to the Model View Controller (MVC) design pattern? I know I should create separate classes to implement my data structures and that my controller classes can pass messages to them from the view, but are there any other organizational considerations I should examine? Especially those particular to Cocoa Touch, Xcode, or iOS?

Other particulars: Playback of pre-recorded and perhaps user-generated audio will also be essential. I know these are model elements, but how exactly they relate to the "V" and the "C" I'm still a bit fuzzy on. I suppose when a user action requires audio playback, the CONTROLLER should pass a message to the MODEL to ready the appropriate sounds, but where exactly should regulation of the playback live? In a "PlayerController" separate from the ViewController I imagine?

Many thanks and pardon my MVC noobery.

解决方案

Caleb gives a good introduction and overview of how to think about the problem. In your particular case, here are some of the pieces you would might have given your description:

  • Clip (M) - Responsible for holding the actual audio data. It would know how to interpret the data and given information about it, but it wouldn't actually play anything.

  • Player (V) - Actually plays a clip on the speakers. Yes, that's a kind of view in MVC. Audio is just another kind of presentation. That said, you'd never call it "PlayerView" because that would suggest it were a subclass of UIView.

  • PlayerView (V) - A screen representation of the Player. Knows nothing about Clips.

  • ClipManager (C) - An object that would keep track of all the clips in the system and manage fetching them from the network, adding and removing them to caches, etc.

  • PlayerViewController (C) - Retrieves a Clip from the ClipManager, and coordinates a Player and a PlayerView to display and play it, as well as any other UI elements (like a "back button" or the like).

This is just an example of how you might break it down for some theoretical audio player app. There are many correct MVC ways to do it, but this is one way to think about it.

这篇关于组织iOS项目的MVC设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆