Question

I have a problem and I will try to explain the issue:

  1. I have one main UIViewController (Whole screen)
  2. I have one secondary UIViewController (setbounds)
  3. I added my secondary view to my mainView using this:

    [mainController.view addSubview:secondaryController.view];   
    
  4. I created a third controller: modalController, I added it to my secondary controller like this:

    [secondaryController presentModalViewController:modalController animated:YES];
    
  5. I make calculus based on some events inside of my modelController.

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

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

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top