Skip to content

Files

Latest commit

822ddf9 · Dec 29, 2015

History

History
59 lines (35 loc) · 3.38 KB

CDLRootViewController.wiki.md

File metadata and controls

59 lines (35 loc) · 3.38 KB

Overview

CDLRootViewController extends UITableViewController, making use of a NSFetchedResultsController to display all Entities of a given type. All configuration is done through a property list file, which is described below.

A CDLRootViewController is instantiated as follows, replacing SomeRootView with the name of the property list file created as described below.

CDLRootViewController *rootViewController = [[CDLRootViewController alloc] initForListViewControllerStructure: [[NSBundle mainBundle] pathForResource:@"SomeRootView" ofType:@"plist"]];

A CDLRootViewController MUST be placed inside a UINavigationController:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

A sample property list file that can be used as a template can be found here: http://coredatalibrary.googlecode.com/files/LIST_VIEW_TEMPLATE.plist*

Implementation Notes

  • Entities must exist as subclasses of NSManagedObject and class files must be generated.

Required Configuration in Property List

The following properties must be present, or CDLRootViewController will throw an exception.

entityName: The name of the Entity to be displayed in the controller as a string. Must be a valid entity in the Core Data model.

sortKeyPaths: Array of keys or keyPaths present in the Enity to sort by. At least 1 is required. No runtime checking happens to verify if the sortKeyPath(s) are valid.

These are converted into NSSortDescriptors using:

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:YES selector:@selector(caseInsensitiveCompare:)]; 

cellTextLabelKeyPath: key path present in the Entity to display as the textLabel property of each cell.

detailViewPropertyListFile: Set the name of the property list file describing the detail view to be shown when a row is selected. If the file is "SomeDetailView.plist", set to "SomeDetailView." Loaded using:

[[NSBundle mainBundle] pathForResource:self.detailViewPropertyListFile ofType:@"plist"]

Optional Configuration in Property List

controllerTitle: Text to display as the title of the view controller as follows:

self.navigationItem.title = controllerTitle; 

sectionKeyPath: key or keyPath to use to create sections in the tableView. Required if you wish to display section index titles.

sectionIndexTitlesEnabled: If sectionKeyPath is present, should section index titles be present on the right side of the table view? Should be boolean YES or NO.

sectionIndexTitlesAlphabetical: If sectionIndexTitlesEnabled is YES, display the full alphabet, rather than the index titles generated by the NSFetchedResultsController. This requires that the sectionKeyPath provides sections that correspond to uppercase letters of the alphabet or #. If you wish to use this property, please follow the steps in the How To guide for creating alphabetical sections

cellDetailTextLabelKeyPath: same as cellTextLabelKeyPath, except for the detailTextLabel property of the cell.