我有一个关于没有为 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,我试图进一步深入了解我所看到的是而不是显示我的ViewController
UIDocumentPickerViewController *dc = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:[self UTITypes] inMode:UIDocumentPickerModeImport];
dc.delegate = self;
[MainVC presentViewController:dc animated:YES completion:nil];
两个委托方法都被调用得很好。我不明白为什么。有人可以在这里帮我吗!提前致谢!!