Chapter 19
Interacting with Collection Views
In the previous chapter, I covered the basics of UICollectionView
. You should now understand how to display items in a collection view. However, you may not know how to interact with the collection view cells. As mentioned before, a collection view works pretty much like a table view. To give you a better idea, I will show you how to interact with the collection view cells, especially about how to handle single and multiple item selections.
We'll continue to improve the collection view demo app. Here is what we're going to implement:
- When a user taps an icon, the app will bring up a modal view to display the icon in a larger size.
- We'll also implement social sharing in the app in order to demonstrate multiple item selections. Users are allowed to select multiple icons and share them on Messages.
Let's first see how to implement the first feature to handle single selection. When the user taps any of the icons, the app will bring up a modal view to display a larger photo and its information like description and price.
The starter project is very similar to the final project we built in the previous chapter. There are only a couple of changes for the Icon
structure. I just changed the Icon
structure a bit to store the name, image, and description of an icon. You can refer to Icon.swift
to reveal the changes.
To continue reading and access the full version of the book, please get the full copy here. You will also be able to access the full source code of the project.