Tutorial 3: Nav Controllers and Segue Question


I was working on building the LocationDetailsViewController ~p95, and had 2 questions:

  1. When do you embed a navigation controller to a view, versus when you just present it modally? I noticed you could still add a navigation bar from the objects library, without a navigation controller. So are there any conventions around this?

  2. Why in the segue for CurrentLocationViewController you set the variables in the other controller to variables inside this controller, while in the segue for the Checklist app, in the AllListViewController, you set it to the sender. What does the sender mean/do?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == “ShowChecklist” {
let controller = segue.destination as! ChecklistViewController
controller.checklist = sender as! Checklist

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == “TagLocation” {
let navigationController = segue.destination
as! UINavigationController
let controller = navigationController.topViewController
as! LocationDetailsViewController
controller.coordinate = location!.coordinate
** controller.placemark = placemark**

Thanks so much!

Hi there,

  1. Embedding in a navigation controller is a little simpler than adding a navigation bar of your own. Either one will work but using a navigation controller is the more common approach. It’s especially useful for when you want to add something like an icon picker like we did in tutorial 2, which is put on the navigation stack.

  2. sender in this context is the thing that caused the segue to happen. In the Checklists app, we trigger that segue by hand and pass along the Checklist object from the table view cell that was tapped. In MyLocations, sender would refer to a button that was tapped and that button doesn’t know anything about the CLLocation object, so that’s why we don’t use sender there.

Does this make sense? :smile:

Ah that helps clarify things. Thanks so much!