三、模型(Model)
模型方法通过数据源和数据含义等协议提供数据,需要实现由控制器触发的回调方法。你需要创建应用程序控制器触发的回调方法,并提供所需的任何委托协议的实现。iPhone SDK 中的数据源可以帮助实现。数据源指任何向另一个对象提供所需数据的对象,其类似于委托,必须在另一个对象中实现它们的方法。它与委托的不同之处在于创建或提供对象而不是针对用户交互作出反应。
苹果文档对于Data Source模式的定义如下:
A data source is almost identical to a delegate. The difference is in the relationship with the delegating object. Instead of being delegated control of the user interface, a data source is delegated control of data. The delegating object, typically a view object such as a table view, holds a reference to its data source and occasionally asks it for the data it should display. A data source, like a delegate, must adopt a protocol and implement at minimum the required methods of that protocol. Data sources are responsible for managing the memory of the model objects they give to the delegating view.