Ch. 16 - Add new checklist - Cancel/Done button do not work

Hi all,

I am having a problem with cancel/done buttons in the Add Checklist scene, in the ListDetailViewController.swift source file.

@IBAction func cancel() {

@IBAction func done() {
    if let checklist = checklistToEdit { = textField.text!
        delegate?.listDetailViewController(self, didFinishEditing: checklist)
    } else {
        let checklist = Checklist(name: textField.text!)
        delegate?.listDetailViewController(self,didFinishAdding: checklist)

Basically they do work, when I click on “cancel” it does not return to the “AllList” scene.

Question 1) Why in the “ItemDetail…swift” the same action contain this code?
navigationController?.popViewController(animated: true )

If I put the same in the ListDetail…swift, then it works

What am I missing?


It sounds like you missed this, at the bottom of page 381:

Next, implement the following delegate methods in AllListsViewController.swift:

// MARK:- List Detail View Controller Delegates
func listDetailViewControllerDidCancel(
                  _ controller: ListDetailViewController) {
  navigationController?.popViewController(animated: true)

The popViewController call can be in the @IBAction func cancel of the detail controller, or in the protocol implementation in the list controller. Putting it in the list controller keeps it with the other code for handling an add or an edit.

That part was correct; I did the chapter from the beginning and now it works fine; I will have a look better to what I missed


This topic was automatically closed after 166 days. New replies are no longer allowed.