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
About the Author
About the Reviewers

Loading data

It's time to load our data so that we can display it in the table view. Loading the data is very similar to the way we checked for files and saved the data in the previous chapter, because both require a specified path in the documents directory to be defined. For our application, we will create a method to load the data and return an array.

Place the following code below the addButtonPressed method:

- (void)loadFoodFromDocumentsDirectory {
    // Get paths from root directory and the main documents directory
    NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0];
    // Get the path to our Data/plist file and where we will be saving our images
    NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
    // Call the file manager to check if the file exists
    NSFileManager *defaultManager = [NSFileManager defaultManager];
    if ...