You may have noticed that when presenting our AddNewViewController
object, we have no way to dismiss the view to get back to the menu. Let's add this functionality now. We will be creating two bar button items that will be text-only items. The first button, Cancel, will dismiss the view while the second, Save, will save the new food entry.
Switch to AddNewViewController.m
and scroll down to viewDidLoad
. Add the following code at the top of viewDidLoad
:
// Add our bar button items UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)]; UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveButtonPressed:)]; // Assign the bar buttons to the navigation controller [self.navigationItem setLeftBarButtonItem:cancelButton]; [self.navigationItem setRightBarButtonItem...