0

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?

wahkiz
  • 616
  • 5
  • 13

2 Answers2

2

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:.

Community
  • 1
  • 1
Cameron Spickert
  • 5,190
  • 1
  • 27
  • 34
1

Hope this helps.

http://www.iphonedevsdk.com/forum/iphone-sdk-development/42658-calling-parent-views-method-subview.html

iPhone how to call a method in parentview from its subview

Community
  • 1
  • 1
visakh7
  • 26,380
  • 8
  • 55
  • 69
  • I eventually got around the problem by making the function in app delegate (where there is an iboutlet to my A viewcontroller), and using the appdelegate function to call the intended function in the A viewcontroller. This is not a good solution, although it works. There has to be a better way. – wahkiz Mar 09 '11 at 06:43