UIDocumentInteractionController remove Actions Menu

烈酒焚心 提交于 2020-01-02 08:34:56

问题


I've been working with the Apple sample code for viewing documents from here:

https://developer.apple.com/library/ios/samplecode/DocInteraction/Listings/ReadMe_txt.html

I have removed all the bits I don't need and got it working pretty much how I would like it to. The problem is I don't want users to have access to the "Actions" menu on the top right of the Document Controller. This appears every time you select a document from the list:

Ideally I would like to remove the button all together, though if I could disable it or disable all the options inside it that would also suffice. I found this question:

Open in + UIDocumentInteractionController : how to filter options in SDK iOS 6 (canPerformActions is deprecated)

But I couldn't figure out how to use the suggestion to disable the options inside the menu. I have uploaded the modified sample code here:

http://plasma.servebeer.com/DocSampleCode.zip

One final note is this will not be going on the App Store it is for private, personal use, so if there is an unofficial way then I would be interested in knowing that too.

Any help would be greatly appreciated, thanks in advance.

Plasma


回答1:


Use UINavigationControllerDelegate

@interface DITableViewController () <UIDocumentInteractionControllerDelegate, UINavigationControllerDelegate>

Assign navigationController delegate to self

- (void)viewDidLoad {

    [super viewDidLoad];
    self.navigationController.delegate = self;
}

Change documentInteractionControllerViewControllerForPreview

- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)interactionController {

    return self.navigationController;
}

Add this UINavigationControllerDelegate method

// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {

    if ([viewController isKindOfClass:[QLPreviewController class]]) {
        viewController.navigationItem.rightBarButtonItem = nil;
    }
}

Update for MP4 files

In MP4 files the action button is on the UIToolbar

- (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if ([viewController isKindOfClass:[QLPreviewController class]]) {
        viewController.navigationItem.rightBarButtonItem.customView = [[UIView alloc] init];
        UIBarButtonItem *item = viewController.toolbarItems.firstObject;
        item.customView = [[UIView alloc] init];
    }
}

N.B. This might not work in future versions of iOS




回答2:


After creating QLPreviewController class you would need to set rightBarButtonItem to nil. Code snippet:

QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.navigationItem.rightBarButtonItem = nil;

I did download project and after execution "Action" button was shown not in the top navigation item, but in the toolbar. Then in this case you would need to subclass QLPreviewController and override viewWillAppear as shown below.

@implementation ExViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSMutableArray *a = [NSMutableArray arrayWithArray:@[]];
    for (NSUInteger i = 0; i < self.toolbarItems.count; i++) {
        if (i == 0) {
            continue;
        }
        [a addObject:self.toolbarItems[i]];
    }
}

@end


来源:https://stackoverflow.com/questions/35116820/uidocumentinteractioncontroller-remove-actions-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!