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 Building the Master and Detail Views Adding Touch Capabilities

Paul Denlinger
Paul Denlinger
2,380 Points

showPlaylistDetail method doesn't work

I have coded the showPlaylistDetail method up and added the gesture recognizer to the PlaylistMasterViewController, but have not been able to get it to move to the PlaylistDetailViewController. Nothing happens. Have checked all my connections, and nothing seems to be out of place. What's wrong?

@IBAction func showPlaylistDetail(sender: AnyObject) { performSegueWithIdentifier("slowPlaylistDetailSegue", sender: sender) }

Paul Denlinger
Paul Denlinger
2,380 Points

I posted the question, and found a typo and changed the spelling of the segue to: "showPlaylistDetailSegue" and checked the identifier to see if the ID matched. There was no error there, and the segue still does not work, so it is not a spelling issue.

can you post the code ?

Paul Denlinger
Paul Denlinger
2,380 Points

Here is the code from PlaylistMasterViewController; thank you.

import UIKit

class PlaylistMasterViewController: UIViewController {

@IBOutlet weak var playlistImageView0: UIImageView!

override func viewDidLoad() {
    super.viewDidLoad()


    let playlist = Playlist(index: 0)
    playlistImageView0.image = playlist.icon
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

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

@IBAction func showPlaylistDetail(sender: AnyObject) {
    performSegueWithIdentifier("showPlaylistDetailSegue", sender: sender)
}

}

2 Answers

D v B v V
D v B v V
20,109 Points

Can you provide your code?

I think you got t the concept of how prepareForsegue works WRONG .. For example lets say we have an array of items that are display on a UITableview controller, Then if you tapped onto a row, it should take you into a new UIViewcontroller which will display in full detail for that specific row. This is how prepare segue happened you don't need no @IBACtion. hope that helps

Paul Denlinger
Paul Denlinger
2,380 Points

Thank you.

I deleted the whole method, and the tap recognizer, and than put them back in, and connected the tap recognizer, and ran a println() in the method and it worked. Not sure exactly why it worked, but it did. Now, I think I have the concept; thank you for explaining.

You welcome :)