如何解决从 UIImagePickerController 将图像分配给 collectionViewCell 中的两个 UIImageView
我在 UITableView 中有一个 UICollectionView。在 UICollectionView 中,每个单元格中有 2 个图像视图。 UIImagePickerController 用于在点击其中一个图像视图时选择图像。
我希望结果是 - 当我单击第一个单元格的 firstPhotoView 并选择应添加到该特定单元格的 imageView 的图像时,依此类推
使用下面的代码,如果我选择一个图像,相同的图像将被添加到单元格中的两个图像视图中。
如何获取有关被点击的单元格的信息并将图像分配给调用 UIImagePicker 的 imageView ?请提出建议。
func collectionView(_ collectionView: UICollectionView,cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AntitipPhotoCollectionCell",for: indexPath) as! AntitipPhotoCollectionCell
cell.cameraIconTappedClosure = { [weak self] in
if self?.imagePicker.sourceType == .camera {
self?.present(self!.imagePicker,animated: true,completion: nil)
} else if self?.imagePicker.sourceType == .photoLibrary {
self?.present(self!.imagePicker,completion: nil)
}
}
if indexPath.row == photosArray.count - 1 {
cell.firstPhotoView.image = photosArray[indexPath.item]
cell.secondPhotoView.image = photosArray[indexPath.item]
}
return cell
}[在此处输入图片说明][1]
func imagePickerController(_ picker: UIImagePickerController,didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let image = info[.originalImage] as? UIImage else {
fatalError("Expected a image")
}
photosArray.append(image)
for cell in servicesCheckListTableView.visibleCells {
let indexPath = IndexPath(item: photosArray.count-1,section: 0)
(cell as? ServicesCheckListableViewCell)?.antiTipPhotoCollectionView.insertItems(at: [indexPath])
(cell as? ServicesCheckListableViewCell)?.antiTipPhotoCollectionView.reloadData()
}
dismiss(animated: true,completion: nil)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。