Вопрос по uiview – Как получить доступ к контроллеру представления супер?

10

У меня проблема, и я постараюсь объяснить проблему:

I have one main UIViewController (Whole screen) I have one secondary UIViewController (setbounds)

I added my secondary view to my mainView using this:

<code>[mainController.view addSubview:secondaryController.view];   
</code>

I created a third controller: modalController, I added it to my secondary controller like this:

<code>[secondaryController presentModalViewController:modalController animated:YES];
</code>

I make calculus based on some events inside of my modelController.

I am able to send messages from my modalController to my secondaryController using:

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

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:

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

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

но нет его контролеру.

Ваш Ответ

1   ответ
32

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

и убедитесь, что это тот контроллер представления, который вы ищете.

Документация Apple о-[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)

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded Alejandra

Похожие вопросы