所以我试图将我的图像数据从我选择的ImagePicker传递到我的UIView上的UI按钮。我已经搜索过但我不熟悉如何使用委托和核心数据。如果有一个更容易和简单的方法,你可以帮助我。顺便说一句,我正在使用ImagePicker库。我只想将AddItemPhotos
张图片传递给btn_firstPhoto
和btn_secondPhoto
。提前谢谢
class AddItemImage: UIView {
@IBOutlet weak var btn_firstPhoto: UIButton!
@IBOutlet weak var btn_secondPhoto: UIButton!
override func awakeFromNib() {
super.awakeFromNib()
// btn_firstPhoto.setImage(AddItemPhotos[0], for: UIControlState)
// btn_secondPhoto.setImage(AddItemPhotos[1], for: UIControlState)
}
}
class AddItemView: UIViewController, ImagePickerDelegate {
var AddItemPhotos: [UIImage] = []
override func viewDidLoad() {
super.viewDidLoad()
setupPicker()
}
func setupPicker() {
var config = Configuration()
config.doneButtonTitle = "Finish"
config.noImagesTitle = "Sorry! There are no images here!"
config.recordLocation = false
config.allowMultiplePhotoSelection = true
let imagePicker = ImagePickerController()
imagePicker.delegate = self
imagePicker.imageLimit = 2
present(imagePicker, animated: true, completion: nil)
}
// MARK: - ImagePickerDelegate
func cancelButtonDidPress(_ imagePicker: ImagePickerController) {
imagePicker.dismiss(animated: true, completion: nil)
}
func wrapperDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
}
func doneButtonDidPress(_ imagePicker: ImagePickerController, images: [UIImage]) {
AddItemPhotos = images
imagePicker.dismiss(animated: true, completion: nil)
}