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 在按钮触摸时打开多个窗口
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
