[英]iOS - how to target the “parent” viewcontroller with initWithViewController
I would like to use a method in a viewcontroller that is the "container" of an other viewcontroller but not directly the parent. 我想在一个视图控制器中使用一个方法,该方法是另一个视图控制器的“容器”,而不是直接父对象。 I display a popover containing a custom xib file. 我显示一个包含自定义Xib文件的弹出窗口。 For that I have three viewcontrollers: 为此,我有三个视图控制器:
1) popoverVC managing the settings of the popover (like alpha value, any arrow, size, and the method I want to use from "outside" dismisspopover) 1) popoverVC管理弹出式窗口的设置(例如alpha值,任何箭头,大小和我要从“外部”使用的方法dismisspopover)
2) customVC with a xib file to change the content of my popover (some text and some buttons). 2)customVC与厦门国际银行文件,以改变我酥料饼的内容(一些文字和一些按钮)。
3) mainVC from where the popover is launched and where I receive some actions when interacting with my buttons in customVC. 3) mainVC从哪里启动弹出窗口,并且在与customVC中的按钮进行交互时收到一些操作。 mainVC is the delegate of customVC. mainVC是customVC的委托。
My problem is I don't know of to call dismisspopover method in popoverVC from an action in customVC. 我的问题是我不知道从customVC中的操作调用popoverVC中的dismisspopover方法。 At the very beginning I initialize my customVC like this from mainVC: 首先,我从mainVC初始化我的customVC:
mainVC.m mainVC.m
customVC *cvc = [[customVC alloc] init];
[cvc setDelegate:self];
PopoverController *popover = [[PopoverController alloc] initWithViewController:cvc];
[popover presentPopoverFromView:textField];
I tried to instantiate a new instance of popoverVC inside my action method in customVC to be able to call the method [popoverdismiss]. 我试图在customVC的action方法中实例化popoverVC的新实例,以便能够调用方法[popoverdismiss]。 But this should not be working since I will be targeting a different instance from the one I started with... And I would like to be able to target popoverVC like [self.presentingVC] but I am not sure the method initWithVC sets a hierarchy like this. 但这不应该起作用,因为我将针对与开始的实例不同的实例...而且我希望能够像[self.presentingVC]这样定位popoverVC,但是我不确定initWithVC方法是否设置了层次结构像这样。
Does anyone has an idea? 有人有主意吗?
The way I usually go about having to circumvent the default view controller hierarchy is to create a property within your child view controller (I think customVC
) called parent
or something to that effect that's of type mainVC
. 我通常必须避开默认视图控制器层次结构的方法是在您的子视图控制器(我认为customVC
)中创建一个称为parent
的属性或具有mainVC
类型的mainVC
。 Then either create a new initializer for your customVC
that incorporates a field to assign to parent
or just assign to it after you first initialize your customVC
. 然后为您的customVC
创建一个新的初始化器,该初始化器并入一个字段以分配给parent
或者在您首次初始化customVC
之后才分配给它。 Then whenever your customVC
needs to ask the mainVC
to perform a function, you can make a method call from parent
. 然后,每当customVC
需要要求mainVC
执行功能时,您都可以从parent
进行方法调用。
Alternatively, you could just as easily make parent
correspond to your popoverVC
object, I'm not totally sure which object you need to access, but it should be as simple as creating your own property for it. 另外,您也可以很容易地使parent
对象对应于您的popoverVC
对象,但我不能完全确定您需要访问哪个对象,但是它应该与为其创建自己的属性一样简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.