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() {
    print("before")
    delegate?.listDetailViewControllerDidCancel(self)
    print("after")
}

@IBAction func done() {
    if let checklist = checklistToEdit {
        checklist.name = 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?

Thanks
Marco

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

Thanks

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