如何访问super的视图控制器? [英] How does one access a super's view controller?
问题描述
我有一个问题,我会尝试解释这个问题:
- 我有一个主要的
UIViewController
(整个屏幕) - 我有一个次要
UIViewController
(setbounds) -
我使用此功能将我的次要资料检视加到我的
mainView
:[mainController.view addSubview:secondaryController.view];
-
我创建了第三个控制器:
modalController
,我添加到我的第二个控制器像这样:[secondaryController presentModalViewController:modalController animated:YES];
-
我根据我的
modelController
。 -
我可以从
modalController
code> secondaryController 使用:[[self parentViewController] performSelector:@selector(myMethodInSecondaryController :) withObject:myObject afterDelay:.5];
注意:self对应于
modalController
-
我需要将myObject传递给我的
mainController
但我不能参考从secondaryController
中的mainController
。我尝试这样:[[self parentViewController] performSelector:@selector(myMethodInMainController :) withObject:myObject afterDelay:。
注意:self对应于
secondaryController
但它不工作,我有权访问我的mainController的视图使用:
self是我的self.view.superview
secondaryController
,但不是其控制器。
在您的辅助控制器中,尝试
code> id mainViewController = [self.view.superview nextResponder];
并检查这是否是您要查找的视图控制器。
Apple的文档 - [UIResponder nextResponder]
:
UIView通过返回管理它的UIViewController对象(如果有)或其superview(如果没有)来实现这个方法
I have a problem and I will try to explain the issue:
- 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];
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 mysecondaryController
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 mymainController
from thesecondaryController
. 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.
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)
这篇关于如何访问super的视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!