Buttons not visible in UIDocumentPickerViewController
Asked Answered
A

2

5

I want to import a document into my application. I have created a Demo to import Document. A demo is working. below is the code of the Demo to open UIDocumentPickerViewController.

-(IBAction) btnOpenClicked{
    UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:[self allowedUTIs] inMode:UIDocumentPickerModeImport];
    documentPicker.delegate = self;

    [self presentViewController:documentPicker animated:true completion:nil];
}

-(NSArray*)allowedUTIs{
    return @[@"public.data",@"public.content",@"public.audiovisual-content",@"public.movie",@"public.audiovisual-content",@"public.video",@"public.audio",@"public.text",@"public.data",@"public.zip-archive",@"com.pkware.zip-archive",@"public.composite-content",@"public.text"];
}

The same code is implemented in my actual project. UIDocumentPickerViewController open and App is able to import file but the issue is that in the actual app I am not able to see any buttons in the header. thought there is action happen but buttons are not visible. Please check screenshot of the Demo and actual app.
enter image description here enter image description here

Acidophil answered 8/1, 2018 at 16:10 Comment(0)
C
7

Your app is probably setting a global UINavigationBar tint color appearance. You can just reset the appearance for UIDocumentPickerViewController only by putting this code somewhere in your application:didFinishLaunchingWithOptions: function and the bar buttons will return to their original blue.

if #available(iOS 11.0, *) {
    UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self]).tintColor = nil
}
Clavicorn answered 19/4, 2018 at 16:52 Comment(5)
Can this not be done on iOS 10? I am trying to do the same but with instance of UIDocumentPickerViewController, but that doesn't seem to do anything?Stile
Not sure about iOS 10, maybe try to inspect the view controller hierarchy to see which one contain the navigation items using a tool like Reveal.Clavicorn
Hm, no, doesn't give me any more information. Thanks though!Stile
is any solution is there for ios 9,same issueDemisec
can you what will be the syntax in objective c??Demisec
C
0

For Objective C:

-> by putting this code somewhere in your application:didFinishLaunchingWithOptions:

[[UINavigationBar 
    appearanceWhenContainedInInstancesOfClasses:
      @[[UIDocumentBrowserViewController class]]] setTintColor: nil];
Chemosynthesis answered 12/1, 2022 at 13:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.