Update: Hands-on with @sensibleCocoa #iOS tableView framework - I see light in the tunnel!
I've got the "Sensible Tableview" installed. I've passed the videos one more time, and now I'm hands-on. Yesterday I tried a small project with some accounting database stuff. But ran into endless problems. So I decided to follow the Core Data video instead, trying to undersand the sensible way.
The video however is showing a XCode 3 project, so there are some small differences. And as "the devil is in the details" it is also present here, and I tumbled. But finally I got it right.
XCode4 has a navigation project template with an example database application that runs out of the box. There isn't any editing posibility however. But by adding a bit of @sensibleCocoa magic, you suddenly get it!
Update: Somehow I discovered that the project didn't save. From the @sensibleCocoa forum I got immediately an answer that solved the problem. I just had to add the following line to the applicationDidEnterBackground method in the navTestAppDelegate.m file:
[self saveContext];
What a relief to have a iOS tableview framework AND decent support!
Create a new Navigation project with Core Data called navTest
Changed the rootviewcontroller.h to:
#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 <CoreData/CoreData.h>
#import "SCTableViewModel.h"
@interface RootViewController : UITableViewController <SCTableViewModelDataSource> {
@private
NSManagedObjectContext *managedObjectContext;
SCTableViewModel *tableModel;
}
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
@end
Changed the rootviewcontroller.m to:
#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];
}
Run it and change the records. It works!