您可以在视图控制器中创建 3 个单独的实例UIDocumentPickerViewController
并检查controller
委托方法中的实例。
private lazy var documentPicker1: UIDocumentPickerViewController = {
let controller = UIDocumentPickerViewController()
controller.delegate = self
return controller
}()
private lazy var documentPicker2: UIDocumentPickerViewController = {
let controller = UIDocumentPickerViewController()
controller.delegate = self
return controller
}()
private lazy var documentPicker3: UIDocumentPickerViewController = {
let controller = UIDocumentPickerViewController()
controller.delegate = self
return controller
}()
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
if controller == documentPicker1 {
} else if controller == documentPicker2 {
}
...
}
或者你可以保留一个属性view controller
来跟踪哪个按钮被点击并在委托方法中检查它。