#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "SCTableViewModel.h"
@interface RootViewController : UITableViewController <SCTableViewModelDataSource> {
@private
NSManagedObjectContext *managedObjectContext;
SCTableViewModel *tableModel;
}
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@end
#import "RootViewController.h"
@implementation RootViewController
@synthesize managedObjectContext = __managedObjectContext;
– (void)viewDidLoad
{
[super viewDidLoad];
// Set up the edit and add buttons.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
action:@selector(insertNewObject)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
SCClassDefinition *eventDef = [SCClassDefinition
definitionWithEntityName:@"Event"
withManagedObjectContext:self.managedObjectContext
autoGeneratePropertyDefinitions:YES];
tableModel = [[SCTableViewModel alloc]
initWithTableView:self.tableView withViewController:self];
// Create and add the objects section
SCArrayOfObjectsSection *objectsSection = [SCArrayOfObjectsSection
sectionWithHeaderTitle:nil
withEntityClassDefinition:eventDef];
objectsSection.addButtonItem = self.navigationItem.rightBarButtonItem;
[tableModel addSection:objectsSection];
}
– (void)dealloc
{
[tableModel release];
[__managedObjectContext release];
[super dealloc];
}
Discussion
No comments yet.