We have CollectionView -> ViewController. In VC, we have a button that displays a picture that I saved via NSUserDefaults (as the correct answer). Of course, we have that in VC, the image stored in memory will pop up in each clicked cell: as it is in ViewDidLoad ()

let imgData1 = defaults.objectForKey("image2") as? NSData if imgData1 != nil { StarTextField.hidden = false TextFieldButton.hidden = true let image = UIImage(data: imgData1!) print("Star is Here") } else { print("Star not Here") } 

Well, finally, the Question itself. How to make sure that not every cell has a saved picture, but where was the check passed?


The issue is resolved, almost))) By adding extra. parameter in the dictionary with the Bool value and its insertion to the comparison. Now I think how to change the Bool parameter in the dictionary.

  • What is the test? Picture in ViewController or in CollectionView ? - VAndrJ
  • when you open any cell, the picture in ViewController (StarTextField) is already in memory and the if condition works on all the cells at once as soon as the cell passes the check: short look: if TextField1.text == navigationItem.title {further save the picture as a valid condition let imgData1 = UIImagePNGRepresentation (StarTextField.image!) Defaults.setObject (imgData1, forKey: "image2") and now it turns out that since the condition worked once and the picture in memory was recorded, then the condition in ViewDidLoad will constantly work. and I need that with each new cell - Alex Gr
  • the condition if TextField1.text == navigationItem.title worked on the new one, with each new cell and on the old cells the condition in ViewDidLoad remained True. There is an idea to add a Bool type parameter (false, True) to the Array and add another 1 parameter to the record in comparison. But because of the lack of experience, it is problematic to figure out how to build it all)) - Alex Gr

0