UIPopoverController 由于某种原因重复自己
一个非常奇特的错误:
我有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几个月前我遇到了同样的问题,以为当我点击任何东西时它会自行消失,但事实并非如此。
我处理这个问题的方法是保留对旧弹出窗口的引用,并在点击
UIBarButtonItem
时将其关闭。您可以使用属性来轻松管理内存,或者自己处理它。
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.You could use a property for easy memory management, or handle it yourself.