How would I extend the chapter example to allow updating and saving in the Details View


#1

I was wondering if someone could provide some guidance on the preferred way to handle a common scenario related to the example in this chapter. When you have a table view and you allow the user to click on a cell to get to a more detailed view, what if you wanted to allow the user to make and save changes while they remain on that details view. In this chapter the authors show how to pass an item for viewing only, but not for updating. To allow updating in the details view, where would you call the ItemStore? Do you have to pass it in to the DetailsViewController similar to how you passed in the item in this chapter? So should the prepare for segue have a second line for the ItemStore, like this?:

detailViewController.item = item
detailViewController.itemStore = itemStore

Or is there a different way of handling this scenario?

One behavior I would like to include is to allow the user to abandon changes. So if they hit the navigation button to get back to the table view and they haven’t yet saved, they will be prompt. If they say no, then changes will not be persisted.


#2

You have pretty much hit the nail on the head, if you are not much concerned about the coupling between the ItemStore and DetailViewController. One thing you could do is make the Item object itself responsible for verifying the changes and for committing them to the ItemStore.