iPhone MVC 问题
我是个新手,有一个关于在 iPhone 编码中遵守 MVC 模型的基本问题。
如何设置一个模型类来保存我的数据并将其连接到以下设置中的不同控制器:
使用 Interface Builder,我创建了一个选项卡控制器,其中
- 选项卡 #1 有一个导航控制器和一个视图控制器层次结构。
- 选项卡 #2 有一个视图控制器
因此,根据我现在的情况,选项卡 #1 下的视图控制器 alloc init 是模型类,我知道如何将模型从一个 ViewController 传递到导航层次结构中的下一个 ViewController,在导航层次结构中它可以传递数据和/或用新数据进行更新。
问题是如何将它从选项卡 #1 的视图控制器传递到选项卡 #2 视图控制器,因为没有链接两者的代码???
预先感谢,
海伦。
I'm bit of a newbie and had a basic question regarding adhering to the MVC model in iPhone coding.
How do I setup a Model class that holds my data and connect it to different controllers in the following setup:
Using Interface Builder, I created a tab controller in which
- Tab #1 has a Nav Controller and a hierarchy of View Controllers.
- Tab #2 has a View Controller
So with what I have now, the View Controller under Tab #1 alloc init's the model class and I know how to pass the model from one ViewController to the next in the Navigation Hierarchy where it can pass the data and/or be updated with new data.
Question is how to pass it from Tab #1's View Controller to Tab #2 View Controller as there is no code linking the two???
Thanks in advance,
Hiren.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这实际上取决于您的应用程序的需求。有多种方法。对于您所描述的,我可能会(a)将模型添加到您的根视图控制器,然后在选择它们时添加/更新各种视图控制器(这里的委托也很有用)或(b)为您的数据模型创建一个单例。
It really depends on your application's needs. There are a number of approaches. For what you've described, I'd probably (a) add a Model to your root view controller, then add/update the various view controllers when they're selected (a delegate here would be useful, too) or (b) create a Singleton for your data model.
我建议让应用程序委托拥有该模型。控制器可以使用
[[UIApplication sharedApplication] delegate]
获取委托并使用属性或方法加载数据。I would suggest having the model owned by the application delegate. The controllers can get the delegate using
[[UIApplication sharedApplication] delegate]
and load data using properties or methods.