单击导航栏时,UIDocumentInterationController项选项菜单不会被忽略

时间:2013-09-09 22:54:57

标签: navigationbar dismiss uidocumentinteraction

标题: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

outputURLViewController.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]到达,而popover仍然可见。'

我的DocumentInteractionControllerDidDismissOptionsMenu:当我点击视图或除导航栏以外的任何其他位置时,它会起作用。那么是否有人阻止任何人点击导航栏中的另一个按钮,直到uidocumentinteractioncontroller被解除或者当他们点击导航栏区域时它被解雇?或者这是一个没有修复的普通错误?

1 个答案:

答案 0 :(得分:0)

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

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

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

这个代码在我的documentInteractionControllerDidDismissOptionsMenu

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

}