//
you're reading...
Social Media

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!

Here is what I did:

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 (nonatomicretainNSManagedObjectContext *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!

About mortjac

Norwegian social entrepreneur, blogger&Swift programmer. PM for the OMG GL standard. Using #ULab to give #Villajoyosa sustainable tourism&tunable pipe organs.

Discussion

No comments yet.

Leave a comment