简体   繁体   English

如何在集合视图中保存图像数组Swift 4

[英]How to save an array of images in a collection view swift 4

When I open my app, the first screen comes up with an empty collectionView of images. 当我打开应用程序时,第一个屏幕上出现一个空的collectionView图片。 I press an 'add' button and it brings me to another viewController . 我按下“添加”按钮,它将带我到另一个viewController This new screen has a collectionView with images inside of each cell . 这个新屏幕具有一个collectionView ,每个cell内都有图像。 When i press on one of the images and press 'create' button. 当我按其中一张图像并按“创建”按钮时。 You are brought to the first screen again and see the image you have just selected in the first cell of the previously empty collectionView . 您将再次进入第一个屏幕,并在以前为空的collectionView的第一个单元格中看到刚刚选择的图像。 I want to save that image in the collectionView , but I can't figure out how. 我想将该图像保存在collectionView ,但我不知道如何。 I tried using userDefault but that didn't work. 我尝试使用userDefault但是没有用。

Thanks for any help. 谢谢你的帮助。

Follow below steps to save image into NSMutableArray . 请按照以下步骤将图像保存到NSMutableArray Using array you can manage your collectionview. 使用数组,您可以管理您的collectionview。

  1. Create and array in your 1st View Controller. 在您的1st View Controller中创建并排列。
  2. Create Delegate into your 2nd View Controller. 创建委托到第二视图控制器。
  3. Implement Delegate into 1st View Controller. 实现委托到第一视图控制器。
  4. When you select Image/Path (Suggested Path), call your delegate and pass your data. 当选择“图像/路径(建议路径)”时,呼叫您的代表并传递数据。
  5. Now you are having that data into your delegate. 现在您将这些数据放入您的委托中。 Add that into your array. 将其添加到您的数组。
  6. Show that array into collectionview. 显示该数组到collectionview中。

Note : This will add same image multiple times into array once you select. 注意 :选择后,这会将同一图像多次添加到数组中。 Manage your array accordingly your requirement. 根据需要管理阵列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM