苹果在 WWDC20 中引入了PHPicker,替代了 UIImagePickerController。
我有一个包装器 NSObject 类,它处理图像选择器控制器的所有配置和呈现,现在我正在替换实现以支持 iOS14。
即使我将委托设置为,self
我也会收到错误:
[Picker] PHPickerViewControllerDelegate doesn't respond to picker:didFinishPicking:
我认为它会检查父视图控制器,确实它没有实现委托方法,但包装器实现了。
这是我的示例代码:
import Foundation
import PhotosUI
class myPicker: PHPickerViewControllerDelegate{
func openFrom(parent:UIViewController!) {
var config:PHPickerConfiguration! = PHPickerConfiguration()
config.selectionLimit = 1
config.filter = nil
let pickerViewController:PHPickerViewController! = PHPickerViewController(configuration:config)
pickerViewController.delegate = self //<---
parent.present(pickerViewController, animated:true, completion:nil)
}
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
picker.dismiss(animated: true, completion:nil)
for result:PHPickerResult in results {
let itemProvider:NSItemProvider = result.itemProvider
print(itemProvider)
}
// ...do something with images...
}
}
使用它...
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let mypicker = myPicker()
mypicker.openFrom(parent: self)
}
你有什么建议?