問題描述
我正在使用 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 在按鈕觸摸時打開多個窗口的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!