【问题标题】:How to use UIDocumentPickerViewController with UINavigationController?如何将 UIDocumentPickerViewController 与 UINavigationController 一起使用?
【发布时间】:2019-11-12 15:12:33
【问题描述】:

我正在尝试将 UIDocumentPickerViewController 推送到 UINavigationController 的堆栈上但是,这会导致看起来像两个导航栏。顶部栏是导航控制器的普通导航栏。下方是包含文档选择器的取消和完成按钮的栏。单击“取消”或“完成”按钮将关闭整个视图。

问题:如何正确地将 UIDocumentPickerViewController 包含到导航控制器的堆栈中,以便取消和完成按钮出现在导航栏中,并导致上一个和下一个视图控制器出现?

【问题讨论】:

    标签: ios uinavigationcontroller uidocumentpickerviewcontroller


    【解决方案1】:

    我相信您应该展示 UIDocumentPickerViewController 控制器而不是将其推入堆栈?我相信它应该被展示出来,因为它带有自己的工具栏。

    是否有特定的原因需要推送?

    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
        }
    }
    

    【讨论】:

    • 我需要推动控制器使其成为多步骤操作的一部分,有点像向导。
    • 您可以尝试隐藏您的导航控制器导航栏以进行该推送,但事情最终可能会变得有点奇怪。
    • 有趣...顺便提一下,iOS 文档是否对组合(或不组合)这些控制器有任何说明?我找不到任何东西。
    • 顺便说一句,您的代码只是基本的视图控制器演示。我建议删除除第一句话之外的所有内容,并尽可能提供支持文档。
    • 我找不到任何文件说你不能这样做,我认为它更像是一种“你可能不应该”的事情。我不得不对 UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentPickerViewController.self]) 的外观做一些小的覆盖,这样你就可以看看类似的东西来帮助你到达你需要的地方。
    猜你喜欢
    • 1970-01-01
    • 2014-05-18
    • 2013-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    相关资源
    最近更新 更多