Sending data from a collection view controller to another view controller object is done in the same way as it is in a table view. Test your memory and see how sending data works in this brief video.
- [Instructor] Our next step is to actually send data…from our CollectionViewController…to our ViewController.…So to do that,…we're going to create a new property…and we'll call this current Item…and that's going to be of the type Item,…so it's going to reference the currently selected item.…And we're going to have it be an optional…so I'll put a question mark right there.…So it could possibly be nil…or not have a value.…
So what we want to do…is when an item is selected,…we're going to set the current item.…I'll do that above performSegue way.…I'm going to hide the navigator…so it's a little bit easier to read the code.…Above performSegue way,…in collectionView didSelectItemAtindexPath,…I'm going to set currentItem…equal to items and the index is going to be indexPath.row.…And then we'll go into prepare for segue-way,…we're going to send that currentItem over…to the other ViewController.…
Before we do that,…we're going to create our property called Item…on that ViewController.…So let's head over to ViewController.swift.…
- Advanced UI controls
- Creating alert controllers
- Displaying web content
- Creating a collection view controller
- Creating a custom data type
- Creating tabbed apps
- Importing and setting icons for your apps
- Publishing your app to the App Store
Skill Level Beginner
iOS and watchOS App Development: Notificationswith Steven Lipton3h 45m Intermediate
1. Mastering Views
2. Display Web Content
3. Collection Views
4. Multi-View Templates
5. Publish an App
Next steps1m 21s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.