Database Reference
In-Depth Information
newMO = [NSEntityDescription insertNewObjectForEntityForName:[entity name]
inManagedObjectContext:context];
[[segue destinationViewController] setRecipeMO:newMO];
}
The second segue branches us into the editing capabilities of our application.
This is our first bit of code reuse.
Instead of having an “add” logic path and an “edit” logic path, the paths are
combined. In fact, their functionality is 99 percent identical. The 1 percent
difference between them concerns whether an object is being created or an
existing object is being edited. By again using dependency injection, we pull
that 1 percent difference out of the logic path and let the parent UIViewController
make the decision. As far as the rest of our editing workflow is concerned,
there is no difference. It is being handed a data object, and it does not matter
whether the object has been created anew or whether it previously existed.
A1.3 The Recipe Detail
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 Figure 45, The recipe detail view ,
on page 214 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 dis-
cussed in Section A1.2, The Recipe List , on page 211 . 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 does not matter if that recipe is new or
existing.
RecipesV1/PPRecipes/PPRDetailViewController.m
- ( 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.
 
 
 
Search WWH ::




Custom Search