Objective-C 多个 popoverviewcontroller

发布于 2024-11-16 23:47:41 字数 140 浏览 3 评论 0原文

我在 UIView 中有多个 popovercontroller。 我可以为一个弹出窗口调用 popoverControllerDidDismissPopover 方法,但无法为所有弹出控制器执行相同的操作。

有人可以建议我,我怎样才能实现这一目标?

I have multiple popovercontroller in a UIView.
I am able to call popoverControllerDidDismissPopover method for one popover but unable to do the same for all the popovercontrollers.

Can anybody suggest me, how can I achieve this ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栀子花开つ 2024-11-23 23:47:41

你能打电话是什么意思?您是否继承了 UIPopoverController 并自己调用该方法?

如果您的意思是“当我的弹出窗口被关闭时它不会被调用”,我们需要更多信息。这是某些情况下的指定行为。让我引用文档中的内容:

弹出窗口控制器不会调用此方法来响应对 dismissPopoverAnimated: 方法的编程调用。如果您以编程方式关闭弹出窗口,则应在调用 dismissPopoverAnimated: 方法后立即执行任何清理操作。

如果您有多个弹出窗口并且想知道哪一个刚刚被关闭,则必须在方法本身中进行比较。

根据您的评论进行编辑:

该方法总是称为popoverControllerDidDismissPopover:(UIPopoverController *)popoverController。此方法由用户关闭的任何弹出窗口触发。如果您有两个需要不同终结的不同弹出窗口,则必须在此方法中区分它们。这就是为什么它有参数,弹出窗口在其中放置 self,一个指向自身的指针。

你的方法应该是这样的:

popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    if (popoverController == myFirstPopoverController)
    {
        //do something
    }

    if (popoverController == mySecondPopoverController)
    {
        //do something else
    }
}

What do you mean you're able to call? Did you subclass UIPopoverController, and call the method yourself?

If you mean "it isn't called when my popovers are dismissed", we need more information. This is specified behavior in some circumstances. Let me quote from the docs:

The popover controller does not call this method in response to programmatic calls to the dismissPopoverAnimated: method. If you dismiss the popover programmatically, you should perform any cleanup actions immediately after calling the dismissPopoverAnimated: method.

If you have multiple popovers and want to know which one has just been dismissed, you'll have to do a comparison in the method itself.

EDIT based on your comment:

The method is always called popoverControllerDidDismissPopover:(UIPopoverController *)popoverController. This method is triggered by any popover that is dismissed by the user. If you have two different popovers that need different finalization, you have to differentiate between them within this method. This is why it has the parameter, in which the popovers put self, a pointer to themselves.

Your method should look like this:

popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
    if (popoverController == myFirstPopoverController)
    {
        //do something
    }

    if (popoverController == mySecondPopoverController)
    {
        //do something else
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文