I need a clearer picture to answer.
for this, I need to step back a little. Please confirm question after question
In Collection View:
Is it correct that you have either like or unlike visible, exclusive: you cannot have bot hidden nor both visible ?
But then, what is the like count in collection view ?
normally you show the number of likes and number of unlike, so both can be visible ? Exact ?
What is self.posts[inverseIndex].peopleWhoLike ? It is an array of people who like ?
If i'm on NewsViewController and i'm pressing like\unlike button-
When you are there, this in fact the detailed corresponding to a single cell of collection view that is displayed ?
This is the post of the author of the post ?
You have only one like / unlike button ?
it's changing the value for UserDefaults(code below for like\unlike buttons)
If you do it this way, without keeping track of which post you are editing, thet will be useless in collection view.
So, what you could do, instead of storing a single bool, would be to store an array of Bool, dimensioned as the size of the collectionView.
But if you need to count likes and count unlike, you should store arrays of Int to keep the count ;
or may be you have to save posts[for the right index]].peopleWhoLike
If I'm going to PostCommentController, which is instantiating to, with the current post cell's data,
I'm recieving the value that changed in UserDefaults(code below) for cellForItemAt in collectionView,
I set the same way in PostCommentController for like\unlike buttons and cellForItemAt(I add a collectionView for the post
in CommentPostController) so it's changing the values in UserDefaults.
If I'm dismissing the view, and go back to NewsViewController, it's changing for each cell in the collectionView its buttons,
like I did set in PostCommentController- so if I did unlike, all of the buttons in each cell in NewsViewController's collectionView is 'unlike'.
How do I change the values for the specific post cell?
Answer will depend on answers above, hence they are really important.
If you have saved arrays (either of Bool or Int), that is what you will have to use to set cell.likeBtn.isHidden with the right index of UserDefaults
Depending also on answers, the best could be to use delegate instead of UserDefaults ; but we should look at this later, once you made it work with UserDefaults.