I have a problem and I will try to explain the issue:
UIViewController
(Whole screen)UIViewController
(setbounds)I added my secondary view to my mainView
using this:
[mainController.view addSubview:secondaryController.view];
I created a third controller: modalController
, I added it to my secondary controller like this:
[secondaryController presentModalViewController:modalController animated:YES];
I make calculus based on some events inside of my modelController
.
I am able to send messages from my modalController
to my secondaryController
using:
[[self parentViewController] performSelector : @selector(myMethodInSecondaryController:) withObject : myObject afterDelay : .5];
NOTE: "self" corresponds to the modalController
I need to pass "myObject" to my mainController
, but i cant make reference to my mainController
from the secondaryController
. I tried this:
[[self parentViewController] performSelector : @selector(myMethodInMainController:) withObject:myObject afterDelay : .5];
NOTE: "self" corresponds to the secondaryController
but it doesn't work, i have access to my mainController's view using : self.view.superview
NOTE: "self" is my secondaryController
but no to its controller.
If you need to find the view controller that is responsible for a particular view, the easiest thing to do is walk the responder chain. This chain is built into all iOS apps, and lets you walk from one view up to its parent view, its grandparent view, and so on, until it reaches a view controller.
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
In your secondary controller, try
id mainViewController = [self.view.superview nextResponder];
and check if this is the view controller you're looking for.
Apple's documentation of -[UIResponder nextResponder]
:
UIView implements this method by returning the UIViewController object that manages it (if it has one) or its superview (if it doesn’t)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With