質問

Ok, I know that the model for the new graphing vc is going to be a subclass of the calculator brain, but how do I get the program stack of the CalculatorBrain from the old VC to the GraphingBrain of my new VC? DO I have to go down the stack on the Storyboard-segue?

I have the pinching and panning on the new axes setup, as well as the delegate to communicate between the new graph brain and graph vc. But isn't my programStack that the user typed in before "trapped" in the old MVC?

I think I've got the concept down, but I don't see the way for that communication to occur.

Thanks in advance!

***For those who don't follow the course, I have two MVCs linked by the NavigationController. The user enters a series of numbers and operations (in the first MVC) which are stored in are then stored in an array in the model of the first MVC. When a button is pressed, it segues to a new MVC, which needs the array that was entered in the previous MVC. How do I transfer that array between two seemingly separate MVCs? I don't think I can have a property in the second VC and set it from the first VC because it(the second MVC) is not instantiated yet. It maybe something with preparteToSegue but I'm not sure.

役に立ちましたか?

解決

Having gone through CS193P (well more than half way there), I think I understand your questions. Here is what you need to remember:

To send a property value down the MVC (C --> V) path and in this case the V holds another MVC; use PrepareForSegue. Regardless of whether the destination has been instantiated or not, you need to do a few things:

  1. Import, in the .h or .m file header of the 1st class, the 2nd class.
  2. In the prepareForSegue, create an instance of the 2nd class and set it to be equal to segue.destinationViewController. You will need to typecast the latter to the second class.
  3. Now you can set the property of this instance you created (of the 2nd class) to any value you want.
  4. You cannot set any IBoutlet values for the second class, from the prepareForSegue, because IBOutlets are not setup until after ViewDidLoad.
  5. For some odd reason, if you do use a condition to check for the segue.identifier, you will need to enclose the statements in {} even if it is only one statement.

Hope this helps and gets the juice flowing...

KMB

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top