我的视图有四个按钮。当你点击一个按钮时,它会启动 PHPickerViewController,允许用户从他们的设备中选择一个图像。我如何知道单击了哪个按钮,以便在该特定按钮上设置所选图像?
@objc func showImage(sender: UIButton){
var configuration1 = PHPickerConfiguration(photoLibrary: .shared())
configuration1.selectionLimit = 1
configuration1.filter = .images
let picker = PHPickerViewController(configuration: configuration1)
picker.delegate = self
present(picker, animated: true, completion: nil)
}
extension ProfileController: PHPickerViewControllerDelegate {
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
dismiss(animated: true, completion: nil)
guard !results.isEmpty else {
return
}
for result in results {
result.itemProvider.loadObject(ofClass: UIImage.self) {
[weak self]
object, error in
DispatchQueue.main.async {
guard let self = self else {
return
}
if let image = object as? UIImage {
}
}
}
}
}
}