I have view controller A, table view controller B and view controller C. In A’s viewDidLoad method I add B as a subview of A. When an outlet in A is tapped then C is presented as a modal view. When an outlet is tapped in C; I need to call some method in B. How can I set B as C’s delegate if there is no direct relationship between the two? Is there another way to do this?
Share
You may need to rethink your design. If “there is no direct relationship between B and C”, then C should not be calling methods on B. If C does need to call methods on B, then there is a relationship.
That said, since your view controller A knows about both of these objects, it can act as the link between them. You can have C call a method on A, which will then call a method on B. Of course, this requires C to have a reference to A; since you say that C is presented when a button is tapped in A, C has such a reference through its
parentViewControllerproperty. For example:It’s possible to make this even more complex — you could even pass a particular selector to A that it could call on B, but at that point I think you would definitely need to reconsider your design and the connections between B and C.