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 Using a Navigation Controller With Segues Modifying the UI

Omotayo Olawepo
Omotayo Olawepo
2,803 Points

Helpp!!!!!! .. Hi my label isn't changing after i press the button and switch to the other viewController

Nothing is showing once i get to the other screen not even the first label. Heres the code

MasterVeiwController

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var aButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        aButton.setTitle("Press me", forState: .Normal)



    }

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


    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "showPlaylistDetailS"  {

            let playlistDetailController = segue.destinationViewController as!
            PlaylistDetailViewController

            playlistDetailController.segueLabelText = "yay!,you pressed me"

        }
    }

}

playlistVeiwController

import UIKit

class PlaylistDetailViewController: UIViewController {

    @IBOutlet weak var buttonPressLabel: UILabel!
    var segueLabelText: String = ""
    override func viewDidLoad() {
        super.viewDidLoad()

        buttonPressLabel.text = segueLabelText
    }

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


}

4 Answers

Omotayo Olawepo
Omotayo Olawepo
2,803 Points

Hey Jhoan

Took the S off the code but it's still not working, it's frustrating i have been stuck on this for a long time now

Jhoan Arango
Jhoan Arango
14,575 Points

Did you change the name of your class from ViewController to PlaylistMasterViewController ??

Omotayo Olawepo
Omotayo Olawepo
2,803 Points

yes i did in the custom class in the utilities the class is

PlaylistMasterViewController

and on the view controller in the identity and type it is called:

PlaylistMasterViewController.swift

Brian Moore
Brian Moore
8,277 Points

Hey Omotayo,

Did you double check that the name of your segue identifier is spelled exactly as you have it in the if segue.identifier == "showPlaylistDetail" { } statement?

the segue itself must be named exactly as you have it named in the code above.

You can check on that if you go to the Main.Storyboard click on the segue between the Playlist and Artists, then go to the Attributes and check the identifier box, it should say "showPlaylistDetail" Make sure that is spelled exactly as you have it in the PlayListMasterViewController Class.

Jhoan Arango
Jhoan Arango
14,575 Points

Hello :

Try checking this, you have a capital S, did you mean to do that ?

if segue.identifier == "showPlaylistDetailS" // Capital S at the end.

Good luck