Master-Detail Application Structure Notes

Here is the basic structure of the Master-Detail template.

In the storyboard, we have the following:

Element
Comments
Navigation Controller
Start of program
Controls segues between master and detail views
sets up the controller area at the top of the views
Cav Master View Controller
Sets up the edit and add buttons
Table presentation of records in one table
Includes setting up the links to the detailed view of each element in the table
Cav Detail View Controller
Gets a reference to a particular element in the table
Presents information about that element
Allows users to change values
Updates database upon exiting this view

Colors:

Class / File
Methods / Variables
Comments
cavAppDelegate.h






UIResponder

window
managedObjectContext
managedObjectModel
persistentStoreCoordinator
saveContext
applicationDocumentsDirectory
cavAppDelegate.m










application

applicationWillResignActive
applicationDidEnterBackground
applicationWillEnterForeground
applicationDidBecomeActive
applicationWillTerminate
saveContext
managedObjectContext
managedObjectModel
persistentStoreCoordinator
applicationDocumentsDirectory
Main.storyboard

information about the views, and the layout of the GUI objects in them
cavMasterViewController.h
UITableViewController
reference to the master view object
fetchedResultsController from the DB
managedObjectContext an internal reference to some or all of a DB
cavMasterViewController.m

















configureCell
interface prototype - see below for implementation
awakeFromNib Called after all NIB (GUI) objects have been created - trivial here
viewDidLoad Often trivial, but in this template two buttons are added to the master view:
> edit
> + to add a new event (= new record in the database)
didReceiveMemoryWarning Trivial here, real apps should do something here
insertNewObject respond to + key, create new record
The right place to give record fields default values
numberOfSectionsInTableView return the number of entries in the table
in this case, the number is the number of records in the database for this table
tableView - numberOfRowsInSection sections are a way to create groups in a table -
in this case, it looks like just one
tableView - cellForRowAtIndexPath
controller calls this to get the cell at an index value
tableView - canEditRowAtIndexPath yes, in our case
tableView - commitEditingStyle possible styles are delete, insert or none -
in our case, the code responds to delete by deleting the object in the context
then saving the context to the database
tableView - canMoveRowAtIndexPath rearrange rows? in our case, no
prepareForSegue There is probably no reason for you to change this code.
called when the user touches any cell -
sets up the call to the detailed view so that view is focused on the record touched by the user
set up by a segue in Xcode from the cell to the detailed view
for more details, see reference for UIStoryboardSegue
information about the connection between the source object (row in table) to destination (detail view)
fetchedResultsController fetch the data from a the database by table name
so the table name needs to match the Entity name in the database
puts the result into the managedObjectContext variable in the template code
controllerWillChangeContent trivial for the template - calls the UITableView method
controller - didChangeSection
updates display when records are added or deleted
controller - didChangeObject
updates the table on insert, delete, update and move events
controllerDidChangeContent
template just stops updating
configureCell template sets display text for cell, could change the cell contents
cavDetailViewController.h
UIViewController

detailItem change type from id to NSManagedObject
detailDescriptionLabel
cavDetailViewController.m




configureView
prototype, see below for function
setDetailItem default is ok
configureView update the fields to display the information in the record
viewDidLoad super and call configureView
didReceiveMemoryWarning super, and whatever
hideKeyboard
new method connected to huge transparent background button to dismiss the keyboard
viewWillDisappear
new method to respond to leaving the detailed view by updating the database
Images.xcassets

images used by the app - icons, for example
cave.scdatamodeld

Information about the GUI interface to define the DB stucture
Frameworks



Foundation
The NS stuff
CoreGraphics
Needed to draw in an app
UIKit
Objects and events for a GUI
CoreData
Handling the SQLite DB
XCTest
Testing stuff