iPhone MVC Question
I'm bit of a newbie an开发者_StackOverflow社区d 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 ControllerSo 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.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.
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.
精彩评论