问题描述
使用UIViewController的实例,有什么方法可以找到用于呈现它的UIPopoverController吗?我还想找到首先显示UIPopoverController的UIViewController。
Using an instance of a UIViewController, is there any way I can find the UIPopoverController being used to present it? I would also want to find the UIViewController that displayed the UIPopoverController in the first place.
我通常会使用委托或其他类型的通知来发送来自显示的信号查看控制器到显示一个,但在这种情况下,我正在尝试创建一个可重复使用的自定义segue,解除弹出窗口,然后移动到主视图中的另一个视图。
I would normally use a delegate or other sort of notification to send a signal from the displayed view controller to the displaying one, but in this case I'm trying to create a reusable custom segue that dismisses the popover and then moves on to another view in the main view.
推荐答案
你会认为这很简单( UIViewController
甚至有私有 _popoverController
property!),但它不是。
You would think that this would be simple (the UIViewController
even has a private _popoverController
property!), but it is not.
一般的答案是你必须保存对 UIPopoverController的引用在创建
UIViewController
时,它所呈现的 UIViewController
中的code>。
The general answer is that you have to save a reference to the UIPopoverController
in the UIViewController
that it is presenting, at the time the UIViewController
is created.
-
如果以编程方式创建
UIPopoverController
,那么就是存储时间的时间参考y我们的UIViewController
子类。
If you are creating the
UIPopoverController
programmatically, then that's the time to store the reference in yourUIViewController
subclass.
如果您使用的是Storyboards和Segues,则可以获得 UIPopoverController
超出 prepareForSegue
方法中的segue:
If you are using Storyboards and Segues, you can get the UIPopoverController
out of the segue in the prepareForSegue
method:
UIPopoverController* popover = [(UIStoryboardPopoverSegue*)segue popoverController];
当然,请确保你的segue真的是一个UIStoryboardPopoverSegue!
Of course, be sure that your segue really is a UIStoryboardPopoverSegue!
这篇关于如何从弹出窗口中显示的UIViewController中找到UIPopoverController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!