UIPopoverController 由于某种原因重复自己

发布于 2024-10-10 13:54:37 字数 606 浏览 0 评论 0原文

一个非常奇特的错误:

我有 BarButtonItem,它会弹出一个 UIPopoverController,如下所示:

-(void) addNewProjectButtonClicked:(id)sender
{
    //Some Preparations....

    [popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

正如预期的那样,Popover 控制器出现在正确的位置。

现在,我期望当我触摸弹出框之外的任何地方时,它会被关闭。
好吧,唯一的问题是,当我再次按下 BarButton(弹出弹出窗口的按钮)时,而不是像我预期的那样关闭旧按钮并呈现新的,结果是 另一个 弹出窗口位于顶部现有的。这意味着当我一次又一次地按下时,我会得到一堆弹出窗口,只有在其他地方多次单击才能将其关闭。

我知道我可以在这里使用一些单例设计模式来解决这个问题,但是没有更简单的内置方法来解决这个问题吗?

谢谢!

A very peculiar bug:

I have BarButtonItem which pops out a UIPopoverController like that:

-(void) addNewProjectButtonClicked:(id)sender
{
    //Some Preparations....

    [popover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

As expected, a Popover Controller appears in the right place.

Now, I'm expecting that when i'm touching ANYWHERE outside the popover it will dismissed.
Well, the only problem is that when I hit the BarButton again (the one that poped the popover) instead of dismissing the old one and presenting a new as i would expect, the result is ANOTHER Popover on top of the existing. that means when i press again and again I get a pile of popovers that can be dismissed only with multiple clicks on somewhere else.

I know i can use some can of Singleton Design Pattern here to solve this, but isn't there an easier and built-in way to take care of it?

Thanks!

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

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

发布评论

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

评论(1

初见你 2024-10-17 13:54:37

几个月前我遇到了同样的问题,以为当我点击任何东西时它会自行消失,但事实并非如此。

我处理这个问题的方法是保留对旧弹出窗口的引用,并在点击 UIBarButtonItem 时将其关闭。

-(void) addNewProjectButtonClicked:(id)sender
{
    [popover dismissPopoverAnimated:YES];
    // Set it up again.
    [popover ...];
}

您可以使用属性来轻松管理内存,或者自己处理它。

I ran into the same problem a few months ago, thought it would dismiss itself when I tapped anything but it's not the case.

The way I'm dealing with this is to keep a reference to the old popover, and dismiss it when the UIBarButtonItem is tapped.

-(void) addNewProjectButtonClicked:(id)sender
{
    [popover dismissPopoverAnimated:YES];
    // Set it up again.
    [popover ...];
}

You could use a property for easy memory management, or handle it yourself.

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