Book Image

Application Development in iOS 7

By : Kyle Begeman
Book Image

Application Development in iOS 7

By: Kyle Begeman

Overview of this book

Table of Contents (15 chapters)
Application Development in iOS 7
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Adding buttons to our navigation bar


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...