所以我有一个可以从相机创建的图像,我想将它传输到另一个具有 UIImage 类型的类,其中已经有一些东西了。该数组连接到 UICollectionView。
我不知道该怎么做,我仍然知道 swift 和编程,但我只是喜欢学习。如果有人有任何建议,我将不胜感激。
这就是collectionView的功能
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! DiscoverCollectionViewCell
cell.titleLable.text = Stuff[indexPath.item]
cell.imageView.image = stuffImages[indexPath.item]
return cell
}
下面是我创建的数组
let stuffImages : [UIImage] = [
UIImage(named: "1")!,
UIImage(named: "2")!,
UIImage(named: "3")!,]
这是我徒劳的尝试在另一个类
var discover = MainViewController()
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
imageCam.image = image
discover.stuffImages[]
picker.dismiss(animated: true, completion: nil)
}
我迷路了,非常感谢您的帮助,谢谢
最佳答案
将 stuffImages 数组更改为静态变量
static var stuffImages : [UIImage] = [
UIImage(named: "1")!,
UIImage(named: "2")!,
UIImage(named: "3")!,]
当您想添加新图像附加到该数组时
MainViewController.stuffImages.append(image)
在MainViewController中重新加载 Collection View
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.collectionView.reloadData()
}
关于arrays - 如何将图像从另一个类传输到 UIImage 数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55849870/