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 Enhance a Weather App with Table Views Implementing the Detail View Passing Data to the Detail View

prepareForSegue not executed

Somehow my prepareForSegue method was not getting called. I had to override tableView method with didSelectRoAtIndexPath and performSegueWithIdentifier to get navigation to work

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { let cell = tableView.cellForRowAtIndexPath(indexPath) tableView.deselectRowAtIndexPath(indexPath, animated: true) performSegueWithIdentifier("showDaily", sender: cell) }

Did I do something wrong, or is the tutorial incomplete?

2 Answers

Kevin Murphy
Kevin Murphy
24,380 Points

Chris you are correct - the steps pertaining to the performSegueWithIdentifier method are missing. I added the tableView method you did as well, the only difference was I don't call didDeselect... I think you can omit that, unless that fixes a use situation I haven't yet encountered. Pretty sure you can take that out though.

Pasan Premaratne please note that the "Passing Data to the Detail View" video concludes without showing the steps to get the segue to execute. Please consider adding a teacher note with the required steps. Thanks.

Pasan Premaratne
Pasan Premaratne
Treehouse Teacher

Table views are automatically wired up to perform segues from master to detail if you use the template. The only reason I can think that it doesn't work is that you may have deleted the segue in your storyboard scene which forces you to call it programmatically.

Another reason might be that you are overriding touch input on a cell to do something else rather than perform the segue.

If you load up a master detail template and hit run, you'll see that the default code already includes segue execution.

Kevin Murphy
Kevin Murphy
24,380 Points

Ah ok Pasan, that makes sense. I have a distant memory lol of choosing the single-view template and adding the tableVC/detailVC from the object library. Thanks for clarifying.