UIStoryboardPopoverSegue opening multiple windows on button touch(UIStoryboardPopoverSegue 在按钮触摸时打开多个窗口)
问题描述
我正在使用 UIStoryboardPopoverSegue
来呈现 iOS 5 iPad 应用的弹出框.Segue 效果很好,但似乎包含按钮的工具栏是弹出框控制器的直通视图,因此如果您继续按下按钮,则会出现更多弹出框.由于我自己没有创建和跟踪 UIPopoverController
(正如故事板所做的那样),当再次触摸按钮时我无法关闭它.有没有其他人遇到过这个?我向 Apple 提出了一个错误,但他们没有回应.
I'm using a UIStoryboardPopoverSegue
to present a popover for an iOS 5 iPad app. The Segue works great, but it seems like the toolbar that contains the button is a passthrough view for the popover controller so if you keep pressing the button, more popovers appear. As I'm not creating and keeping track of the UIPopoverController
myself (as the Storyboard is doing it) I can't dismiss it when the button is touched again. Has anyone else run into this? I have a bug open with Apple but they haven't responded.
编辑:我已经使用下面的答案解决了这个问题.这是我最终使用的代码.currentPopover
是我的视图控制器类中的一个 __weak
ivar,所以当控制器完成时它会自动下降到 nil.
EDIT: I've solved this using the answer below. Here is the code I ended up using. currentPopover
is a __weak
ivar in my view controller class, so when the controller is done it will drop to nil automatically.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue isKindOfClass:[UIStoryboardPopoverSegue class]]){
// Dismiss current popover, set new popover
[currentPopover dismissPopoverAnimated:YES];
currentPopover = [(UIStoryboardPopoverSegue *)segue popoverController];
}
}
推荐答案
您必须存储对作为 UIStoryboardPopoverSegue
类的一部分传递的 popoverController
属性的引用prepareForSegue
类方法.
You have to store a reference to the popoverController
property passed as part of the UIStoryboardPopoverSegue
class in the prepareForSegue
class method.
要访问它,请像这样覆盖调用视图控制器中的方法:
To access it, over-ride the method in the calling view controller like this:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// The Storyboard Segue is named popover in this case:
if ([segue.identifier compare:@"popover"] == NSOrderedSame) {
// segue.popoverController is only present in popover segue's
// self.seguePopoverController is a UIPopoverController * property.
self.seguePopoverController = segue.popoverController;
}
}
然后你可以用通常的方式关闭它.
Then you can dismiss it in the usual way.
这篇关于UIStoryboardPopoverSegue 在按钮触摸时打开多个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:UIStoryboardPopoverSegue 在按钮触摸时打开多个窗口
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01