Collection-View-in-a-Table-View-Cell
Collection-View-in-a-Table-View-Cell copied to clipboard
Using information from the cells
Hi Ash! I have some doubts:
I would like to put different images in every cell and depending on which one the user selects (and knowing through the code which one was selected) I would provide and work with different numbers. Where would be the ideal part to do so and how? I thought of adding a button inside every Collection View Cell, but I don't know if that would be better or how I would manage every different replicated button.
Also, I would only like to have 4 rows, but I'd like to have specific and different numbers of cells for each one of the rows. How can I achieve that?
Thank you.
Hi there, you can customize each cell by using the collection view data source functions. Same for customizing the number of cells in each row. You can read more about how this works and my rationale in my tutorial.
Thank you Ash!! I've got one more question:
- I'm trying to follow your tutorial in a different way now. Instead of using a Table View Controller in the storyboard, I've got a basic View Controller (the basic you're given right at the beginning). I use the top half to show some data and stuff, and I'd like the bottom half to contain a Table View, which would have the same your Table View Controller had. I tried to follow the very same steps, the only difference (to me) is that the main class I'm using looks like this:
class ViewController: UIViewController, UITableViewDataSource
So after everything is ready and passes the building, I've got the following execution error:
MyProject.TableViewCell collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance
What could the trouble be? Thank you again.
The error suggests that the table view cell is the data source of the collection view. I'd recommend using the ViewController instead: class ViewController: UIViewController, UITableViewDataSource, UICollectionViewDataSource
Awesome! It was a silly mistake indeed, but another really strange error occurs during execution. All table rows are generated correctly, but every Collection View is empty. I set a blue color for them in the storyboard but then nothing else is inside. I even tried printing information with
collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
in case there's really something you can push, but still all the rows with their collection views seem empty. The rest of the code for the collection view cells is just the same as the code in your tutorial :(
It's hard to say without the project in front of me. These kinds of problems are common when you're first learning a new programming technique like the one I explained in the tutorial. I would suggest listing all your assumptions and verifying them, add print statements or breakpoints to verify data source methods are being called, double-check storyboard IBOutlet connections, etc. This process can be frustrating, but it gets easier with practice. Good luck!
Thank you so much!! :D