如何从弹出窗口中显示的UIViewController中找到UIPopoverController?

编程入门 行业动态 更新时间:2024-10-11 03:20:28
本文介绍了如何从弹出窗口中显示的UIViewController中找到UIPopoverController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用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的引用

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 your UIViewController 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?

    本文发布于:2023-11-08 20:46:38,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1570412.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:弹出   中找到   窗口中   UIViewController   UIPopoverController

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!