Search code examples
iosuidocumentpickervcfiles-app

UIDocumentPickerViewController buttons look disabled but work -- why?


I am using UIDocumentPickerViewController to export images to the Files app in iOS 11. The picker comes up, and I am able to pick a destination for the files. I get the callback that the files were moved and I can see them in Files, so that appears to be working fine. However, the UI is wrong -- the Add and Cancel buttons look disabled, but they actually work fine. The buttons don't look this way if I just use Save to Files in the Share Sheet.

This is my code:

UIDocumentPickerViewController *docPicker = 
[[UIDocumentPickerViewController alloc] initWithURLs:self.assetURLs inMode:UIDocumentPickerModeExportToService];

docPicker.delegate = self;
[vc presentViewController:docPicker animated:YES completion:nil];

Things I have tried:
1) I have tried both Move and Export types
2) I have enabled the iCloud capability (all three items: key-value, Document, and CloudKit) - no difference in the experience [in fact, the code worked even without these set, though the docs say otherwise])

Here is an screenshot of what the UI looks like. As you can see, the UI says it will add the item to the chosen directory (and it, in fact, does if I tap on Add):

enter image description here

Anyone know how to get the buttons to appear blue and look enabled? I have not found any sample code online that I could try -- if someone has a pointer, I can try that to see if it's something about my configuration or code.


Solution

  • Based on your comment, your app is setting the tintColor using UINavigationBar.appearance. This will affect all navigation bars, including those of system navigation controller such as UIDocumentPickerViewController.

    I've dealt with this in one of my own apps. One solution is to subclass UIDocumentPickerViewController and to use your subclass anywhere you need the picker view. In your subclass, override viewDidLoad and set UINavigationBar.appearance.tintColor back to nil. And also override viewWillDisappear to reset UINavigationBar.appearance.tintColor back to the desired color.