问题描述
我有一个问题,我会尽力解释这个问题:
I have a problem and I will try to explain the issue:
- 我有一个主要的
UIViewController
(全屏) - 我有一个辅助
UIViewController
(setbounds) 我使用以下方法将辅助视图添加到了
mainView
:
- I have one main
UIViewController
(Whole screen) - I have one secondary
UIViewController
(setbounds) I added my secondary view to my
mainView
using this:
[mainController.view addSubview:secondaryController.view];
我创建了第三个控制器:modalController
,我像这样将它添加到我的辅助控制器:
I created a third controller: modalController
, I added it to my secondary controller like this:
[secondaryController presentModalViewController:modalController animated:YES];
我根据 modelController
中的一些事件进行微积分.
I make calculus based on some events inside of my modelController
.
我可以使用以下命令将消息从我的 modalController
发送到我的 secondaryController
:
I am able to send messages from my modalController
to my secondaryController
using:
[[self parentViewController] performSelector : @selector(myMethodInSecondaryController:) withObject : myObject afterDelay : .5];
注意:self"对应于modalController
我需要将myObject"传递给我的 mainController
,但我无法从 secondaryController
引用我的 mainController
.我试过这个:
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];
注意:self"对应于secondaryController
但它不起作用,我可以使用以下命令访问我的 mainController 视图:self.view.superview
but it doesn't work, i have access to my mainController's view using : self.view.superview
注意:self"是我的secondaryController
但对它的控制器没有.
but no to its controller.
推荐答案
在你的辅助控制器中,尝试
In your secondary controller, try
id mainViewController = [self.view.superview nextResponder];
并检查这是否是您正在寻找的视图控制器.
and check if this is the view controller you're looking for.
Apple 的 -[UIResponder nextResponder]
文档:
Apple's documentation of -[UIResponder nextResponder]
:
UIView 通过返回管理它的 UIViewController 对象(如果有)或它的超视图(如果没有)来实现这个方法
这篇关于如何访问超级视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!