0

标题:UIDocumentInteractionController 在导航栏中单击任何位置时关闭弹出窗口。

我的代码可以找到。它在我的 iPhone 和 iPad 模拟器中运行良好。它可以满足我的要求。但是,我的问题是取消默认的弹出菜单。如果我单击视图区域,它就会消失,如果我在弹出窗口中选择一个选项,它就会消失,如果我单击标签栏区域,它也会消失。这很好。但是,如果我单击导航栏中的任何位置,它就会保持不变。如果我单击导航栏中的任何项目,它就会崩溃。如果我也单击导航栏,我希望默认弹出窗口关闭。

outputURLViewController.h

#import <UIKit/UIKit.h>

@interface outputURLViewController : UIViewController<UIDocumentInteractionControllerDelegate,UIPopoverControllerDelegate>
{
    IBOutlet UIWebView *previewWebView;
}

@property (nonatomic, strong) NSString *outputURLString;
@property (nonatomic, strong) NSString *outputURLName;
@property (nonatomic, retain) UIWebView *previewWebView;
@property (nonatomic, strong) UIDocumentInteractionController *docController;
- (IBAction)actionButton:(id)sender;

@end

输出URLViewController.m

#import "outputURLViewController.h"

@interface outputURLViewController ()
{
    NSArray *myButtonArray;
    UIBarButtonItem *myActionButton;
}
@end

@implementation outputURLViewController
@synthesize outputURLString;
@synthesize outputURLName;
@synthesize previewWebView;
- (void)viewDidLoad
{
    [super viewDidLoad];
    //Creates my action put and put it in the right side of navigation bar
    myActionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionButton:)];
    myButtonArray =[[NSArray alloc] initWithObjects:myActionButton, nil];
    self.navigationItem.rightBarButtonItems = myButtonArray;

    NSURL *url = [[NSBundle mainBundle] URLForResource:outputURLString withExtension:@"pdf" subdirectory:@""];

    //displays my document in the webview
    [previewWebView loadRequest:[NSURLRequest requestWithURL:url]];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

//action that display my options in a default popup menu   
- (IBAction)actionButton:(id)sender
{
    NSURL *url = [[NSBundle mainBundle] URLForResource:outputURLString withExtension:@"pdf" subdirectory:@""];
    if (url) {
        self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
        self.docController.delegate = self;
        [self.docController presentOptionsMenuFromBarButtonItem:myActionButton animated:NO];
    }
}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application{}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application{}
//dismiss my popup menu in the view, but not the navigation bar when click
- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller{}
@end

如您所见,它非常简单的默认弹出菜单代码。它做我想要的。我只是想弄清楚如何在弹出窗口消失之前单击导航项按钮时防止它崩溃。

我得到的错误是:

由于未捕获的异常“NSGenericException”而终止应用程序,原因:“-[UIPopoverController dealloc] 在弹出窗口仍然可见时达到。”

我的 DocumentInteractionControllerDidDismissOptionsMenu: 当我单击视图或导航栏以外的任何其他位置时确实有效。那么有没有办法阻止任何人点击导航栏中的另一个按钮,直到 uidocumentinteractioncontroller 被解除或在他们点击导航栏区域时将其解除?或者这是一个没有修复的正常错误?

4

1 回答 1

0

决定在弹出窗口处于活动状态时隐藏导航项。

我在 myActionButton 部分使用了这段代码

if ( IDIOM == IPAD ) {
    self.navigationItem.rightBarButtonItem = nil;
    self.navigationItem.hidesBackButton = YES;
}

和我的文档中的这段代码InteractionControllerDidDismissOptionsMenu

if ( IDIOM == IPAD ) {
    self.navigationItem.rightBarButtonItem = myActionButton;
    self.navigationItem.hidesBackButton = NO;

}
于 2013-09-17T21:38:26.070 回答