In this challenge, combine the two approaches you've already learned to wrap up the cell selection functionality.
This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4448-beginning-collection-views/lessons/6
In this challenge, combine the two approaches you've already learned to wrap up the cell selection functionality.
Hello!
I’m loving this tutorial, it’s been very helpful.
I was praticing by myself and don’t know how to do something.
Let’s say I have 10 cells in my collection view. When I select the first cell, it will go to another view controller with a custom view, where I have few buttons and text fields. When I selet the second cell, it will go to the same view controller but will have few image views and labels. So, each cell with open the same view controller but will load different views. I have no idea how to do that.
Ps. Sorry if it is a begginer question, I’m just starting with programming.
You should be able to implement the above quite easily using a segue to the new view controller from your collection view. In your view controller containing the collection view, you’d need to implement the prepare(for:sender:)
method where you do the necessary set up before moving to a new view controller via a segue. In that method, you’d check to see which cell initiated the segue and then pass on a value to the destination view controller which indicates how the destination view controller should behave.
So, when your destination view controller loads, it will first check the property set by the prepare(for:sender:)
method in the parent view controller and then set up the display accordingly.
Hope this helps