When users select a recipe in our application, we want to display everything about the recipe in one screen so they can easily absorb the information and prepare the recipe. We’ll need one fairly complex UIViewController in order to give them that one-screen access. Take a look at the following screenshot for a sample of the view.
In our UIViewController, we’ll take the data object that was passed to us and display it in one (potentially) lengthy UIScrollView.
The edit button in the UINavigationBar is the interesting part of this view controller. When the edit button is clicked, we enter the edit workflow (we’ll discuss this further in the next section). This process is identical to the add workflow we discussed in The Recipe List. With this code reuse, we can now enter the same workflow from the view controller that allows us to view a recipe as we did from the list recipes view controller. Both of these produce the same effect: we can edit a recipe, and it doesn’t matter if that recipe is new or existing.
| - (void)prepareForEditSegue:(UIStoryboardSegue *)segue sender:(id)sender |
| { |
| id controller = [segue destinationViewController]; |
| [controller setRecipeMO:[self recipeMO]]; |
| } |
Note the subtle difference in this reuse. In the previous version of the edit workflow, we created a new data object. In this version, we take our existing reference to the data object and hand it off to the edit workflow.