Question

J'ai un problème et je vais essayer d'expliquer le problème:

  1. J'ai un UIViewController principal (écran complet)
  2. J'ai un UIViewController secondaire (setbounds)
  3. J'ai ajouté ma vue secondaire à ma mainView en utilisant ceci:

    [mainController.view addSubview:secondaryController.view];   
    
  4. J'ai créé un troisième contrôleur: modalController , je l'ai ajouté à mon contrôleur secondaire comme suit:

    [secondaryController presentModalViewController:modalController animated:YES];
    
  5. Je calcule en fonction de certains événements de mon modelController .

  6. Je peux envoyer des messages de mon modalController à mon secondaryController en utilisant:

    [[self parentViewController]  performSelector : @selector(myMethodInSecondaryController:) withObject : myObject afterDelay : .5];
    

    REMARQUE: "auto". correspond au modalController

  7. Je dois passer "myObject". à mon mainController , mais je ne peux pas faire référence à mon mainController à partir du secondaryController . J'ai essayé ceci:

    [[self parentViewController] performSelector : @selector(myMethodInMainController:) withObject:myObject afterDelay : .5];
    

    REMARQUE: "auto". correspond au secondaryController

    mais cela ne fonctionne pas, j'ai accès à la vue de mon contrôleur principal avec: self.view.superview

    REMARQUE: "auto". est mon secondaryController

mais non à son contrôleur.

Était-ce utile?

La solution

Dans votre contrôleur secondaire, essayez

id mainViewController = [self.view.superview nextResponder];

et vérifiez s'il s'agit du contrôleur de vue que vous recherchez.

Documentation Apple sur - [UIResponder nextResponder] :

  

UIView implémente cette méthode en renvoyant l’objet UIViewController qui la gère (s’il en a un) ou son superview (si ce n’est pas le cas)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top