简体   繁体   English

如何将 UIDocumentPickerViewController 与 UINavigationController 一起使用?

[英]How to use UIDocumentPickerViewController with UINavigationController?

I'm trying to push a UIDocumentPickerViewController onto a UINavigationController's stack However, this results in what looks like two navigation bars.我正在尝试将 UIDocumentPickerViewController 推送到 UINavigationController 的堆栈上但是,这会导致看起来像两个导航栏。 The top bar is the normal navigation bar of the navigation controller.顶栏是导航controller的普通导航栏。 Beneath that is the bar containing the document picker's Cancel and Done buttons.下方是包含文档选择器的取消和完成按钮的栏。 Clicking on the Cancel or Done buttons dismisses the entire view.单击“取消”或“完成”按钮将关闭整个视图。

Question: How can I properly include a UIDocumentPickerViewController onto a navigation controller's stack, so that the Cancel and Done buttons appear in the navigation bar, and cause the previous and next view controllers to appear?问题:如何正确地将 UIDocumentPickerViewController 包含到导航控制器的堆栈中,以便取消和完成按钮出现在导航栏中,并导致上一个和下一个视图控制器出现?

I believe you should be presenting the UIDocumentPickerViewController controller instead of pushing it onto the stack?我相信您应该展示 UIDocumentPickerViewController controller 而不是将其推入堆栈? I believe it's supposed to be presented because it comes with its own toolbar.我相信它应该被展示,因为它带有自己的工具栏。

Is there a specific reason it needs to be pushed?是否有需要推送的特定原因?

func presentPicker() {

    var documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(documentTypes: ["public.text"], inMode: UIDocumentPickerMode.Import)
    documentPicker.delegate = self
    documentPicker.modalPresentationStyle = UIModalPresentationStyle.FullScreen
    self.presentViewController(documentPicker, animated: true, completion: nil)

}

extension viewController: UIDocumentPickerDelegate {
    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
        // handle picked Document
    }

    func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
        // pop view controller
    }

    func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
        // handle picked Document
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM