access variable of a view controller from a pushed view controller
I am using a navigation view controller to handle two view controllers; one each for the landscap开发者_如何学Ce and portrait orientations.
Now, I need to set a propery belonging to the view controller A(for vertical) that pushed the view controller B (for horizontal), from the view controller B. Is there any way I can achieve this? Sample codes and examples are welcome :) Thanks!To get from A to B:
Define a property on view controller B to house the variable. In the code where you create view controller B, before you push it, set the property to A's value.
To get from B to A:
when you create B, use addObserver:forKeyPath:options:context:
to add A as an observer of the property on B. Then when B changes, you get a change notification, and you can update the property on A. See the KVO section here.
精彩评论