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

iOS Build a Playlist Browser with Swift Refactoring Our Code Tapping On Our Playlists

HELP! When I click on each icon, they all bring me to the same playlist detail view? (Playlist Browser Swift)

I don't have any errors in the build. I am guessing something is weird with my code. Each icon/placeholder brings me to the first yellow view (Rise and Shine). Any help would be appreciated. Thanks.

2 Answers

Karl Metum
Karl Metum
3,447 Points

It feels like you have forgotten to add the correct index when calling Playlist(index: index) and that you are calling Playlist(index: 0) instead.

Check if your prepareForSegue method looks like this inside PlaylistMasterViewController:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  if segue.identifier == "showPlaylistDetailSegue" {
    let playlistImageView = sender!.view as! UIImageView
    if let index = playlistsArray.indexOf(playlistImageView) {
      let playlistDetailController = segue.destinationViewController as! PlaylistDetailViewController
      playlistDetailController.playlist = Playlist(index: index)
    }
  }
}

Thanks for pointing that out!