【发布时间】:2019-01-17 11:25:10
【问题描述】:
我有一个关于没有为 DocumentPickerViewController 调用委托方法的查询,这是背景,我只需要从我的文件应用程序中导入任何可用的资源,因此我正在使用 UIDocumentPickerViewController。
我有一个单独的 ViewController,我将 documentPickerViewController 的视图添加为子视图并添加它的委托。我的 ViewController 的代码是这样的。
var documentPickerController: UIDocumentPickerViewController!
let supportedUTI = [kUTTypeImage,kUTTypeSpreadsheet,kUTTypePresentation,kUTTypeDatabase,kUTTypeFolder,kUTTypeZipArchive,kUTTypeVideo, kUTTypeAudiovisualContent]
documentPickerController = UIDocumentPickerViewController.init(documentTypes: supportedUTI as [String], in: .import)
documentPickerController.delegate = self
documentPickerController.allowsMultipleSelection = false
view.addSubview(documentPickerController.view)
现在我看到pickercontroller 已打开,当我点击取消时会调用documentPickerWasCancelled,但当我选择文件时不会调用documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]。
如果我像这样直接显示pickerViewController
UIDocumentPickerViewController *dc = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:[self UTITypes] inMode:UIDocumentPickerModeImport];
dc.delegate = self;
[MainVC presentViewController:dc animated:YES completion:nil];
这两个委托方法都被调用得很好。我不明白为什么。有人可以在这里帮我吗!提前致谢!!
【问题讨论】:
-
您使用的是什么版本的 iOS?
documentPicker(_:didPickDocumentsAt:)(URL 数组)是在 iOS 11 中添加的,而documentPicker(_:didPickDocumentAt:)(单个 URL)当时已被弃用,但已被以前的版本使用。
标签: ios swift uidocumentpickervc uidocumentpickerviewcontroller