Basically, the view hierarchy is like this :
A (UIViewController class)
- B (subview of A.view)(UIView Class)
B, has a class, and one of the functions requires getting some info from A.
What is the best way to invoke a function in A from B?
Basically, the view hierarchy is like this :
A (UIViewController class)
- B (subview of A.view)(UIView Class)
B, has a class, and one of the functions requires getting some info from A.
What is the best way to invoke a function in A from B?
If B is a subview of A, [B superview]
is A.
Update 1
If you're looking for the view controller for which A is the view
, check out this response to a similar question. To summarize, according to the UIResponder documentation, if an instance of UIView
is the view
of a UIViewController
, its nextResponder
will be the view controller (else, nextResponder
is its superview
).
Update 2
If A is the controller, and B is A.view's subview, you can get to A like so:
UIResponder *A = [[B superview] nextResponder];
Keep in mind that nextResponder
's return type is UIResponder *
, so you might want to verify that A is actually a UIViewController
using isKindOfClass:
.
Hope this helps.