0

Apple states that the UIDocumentBrowserViewController should be the rootviewcontroller of your app. https://developer.apple.com/documentation/uikit/view_controllers/adding_a_document_browser_to_your_app

I have done it this way but I have some UX problem that I cant tackle. I cant find a good UX solution for navigating back into my App (switching back the app windows rootviewcontroller again to whatever I want).

However I have found that there are some properties where I can manipulate the appearance of the control, "Use the additionalLeadingNavigationBarButtonItems and additionalTrailingNavigationBarButtonItems methods to add buttons to the navigation bar.", but these wont add items to the "main" menu (where I can select other FileProviders, drive dropbox etc.) and where the possibility of going back would be the most clear.

Does anyone implemented, knows a good solution for adding a back button, FAB, back swipe gesture, or something for UIDocumentBrowserViewcontroller which is presented in a as the apps rootviewcontroller?

Im looking for a solution when the user ended the browsing of documents in the UIDocumentBrowserViewcontroller(copy,import etc) and wants to go back to another Viewcontroller.

  • It isn't completely clear what you are looking for. Are you looking for what the UX should be when a user wants to close a document they have opened so they see the document browser again? Or are you looking for how to make the document browser visible again from a code perspective? – theMikeSwan Jan 10 '18 at 16:10
  • If the UIDocumentBrowserViewController is your root view controller then there is no concept of 'back' from it as it's the top most controller. You will always be going forwards to some other view controller. Perhaps the UIDocumentPickerViewController might be better for your needs as is suggested in that documentation. – Upholder Of Truth Jan 10 '18 at 16:56
  • why do you think? i mean apples limitation is that i must present it as the windows rootviewcontroller but if i change it to go to another it is okay. – tryhardgeci Jan 10 '18 at 16:59
  • Actually for me it is unclear what you exactly want as well... But which might give you a hint is my app that I created with `UIDocumentBrowserViewController`: https://itunes.apple.com/us/app/spicker-2/id1333567829?mt=8 – Nico S. Feb 15 '18 at 01:45
  • 1
    What do you mean, navigating back into your app? UIDBVC is intended to be the main UI of your app. Are you looking for UIDocumentPickerViewController instead? – Thomas Deniau May 18 '18 at 16:50

1 Answers1

0

A great solution for this is to add a custom button through the additionalTrailingNavigationBarButtonItems or additionalLeadingNavigationBarButtonItems property. Example below:

let documentBrowser = UIDocumentBrowserViewController(forOpening: [.jpeg, .png])
let cancelButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(didTapDocumentBrowserCancel))
documentBrowser.additionalTrailingNavigationBarButtonItems = [cancelButton]

Then create a function to close the document browser.

@objc private func didTapDocumentBrowserCancel() {
    dismiss(animated: true)
}

References: