Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jason Brown](https://secure.gravatar.com/avatar/141939d19c5277fb69100e39c619d1ff?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jason Brown
2,412 PointsWhat value should I pass through a segue to access a Detail view of an item in a collection?
I am trying to use a collection to build a relatively simple Master/Detail view program and I cannot figure out how to pass the right data through my segue to show the relevant detail view.
My data is structured as a nested array with several sections and rows. The section and row references point to a dictionary with the information I would like to present on the Detail view when someone selects an item from the collection.
To display the images in the collection I used the following structure:
let image = UIImage(named: menuList [indexPath.section][indexPath.row]["Image"]!) cell.imageView.image = image
I have tried two approaches to passing the cell information through the segue; however I can't get either to work.
I don't understand the syntax to use the find function in a nested array to pass the information the same way as the Playlist app. I also cannot find the right way to pass along the index path information from the selected cell through the segue.
Any advice on how I can pass the correct reference through would be greatly appreciated!
1 Answer
![Greg Kaleka](https://secure.gravatar.com/avatar/54c2cac346df05d7b70cc0a6825c1cba?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Greg Kaleka
39,021 PointsYou'll be using the indexPath
for the row that was selected to pass the appropriate data to your detail view. You'll need some control flow using if
or switch
statements (or both!). For example:
let tableSec = indexPath.section
let tableRow = indexPath.row
switch tableSec {
case 0:
switch tableRow {
case 0:
// pass data for your array[0][0]
break
case 1:
// pass data for your array[0][1]
break
case 2:
// pass data for your array[0][2]
break
case 1:
// pass data for your array[0][0]
break
}
case 1:
switch tableRow {
case 0:
// pass data for your array[1][0]
break
// etc.
}
}
Make sense?
Jason Brown
2,412 PointsJason Brown
2,412 PointsHi Greg,
The actual data set I'm using is quite huge, so I have simplified it somewhat to illustrate the same structure.
Greg Kaleka
39,021 PointsGreg Kaleka
39,021 PointsThanks Jason. - you may want to re-format your comment with proper markdown. Check out the Markdown Cheatsheet link below the text area while you're building your comment.
Anyway, I'll update my answer above based on your code here.