How can I share a model between multiple storyboard views?
The situation:
I'm writing my first iPhone app; it's an opengl game and I want to use separate views... The first view is the menu screen, a normal UIView/UIViewController with a high scores list and some buttons for configuring and starting a new game. The second view is a GLKView/GLKViewController combo, which will display the game.
I have a model, which includes the game state, player data, the high scores list, etc. I need to share this model between the two views. I've seen examples of this before, where the model is instantiated in the application delegate, and references to it are passed to each view controller that needs access to it. I'd do it that way, but I don't know how to access the view controllers in my storyboard.
My questions:
Is this the way I should be doing things? To reiterate, I want my model to be owned by the AppDelegate, and I will pass references to the view controllers from the application:didFinishLaunchingWithOptions: method. If there's a better way to solve this problem, please let me know.
Assuming the above is the right way to do things, how would I go about doing it? I'm not sure how to access the items in the storyboard.
Since the app delegate has references to the view controllers as well as the model, it should be able to update whichever view is currently active whenever the model changes.
Ideally, the model shouldn't be talking directly to the views: it should tell the app delegate that it has changed, and then the app delegate will tell the appropriate view to update.
I think this is the question you're asking; if it's not, let me know what I'm missing and I'll try answering again.
链接地址: http://www.djcxy.com/p/52406.html上一篇: 对象在视图控制器中共享