Skip to content

Instantly share code, notes, and snippets.

@mafis
Created November 20, 2009 11:54
Show Gist options
  • Save mafis/239452 to your computer and use it in GitHub Desktop.
Save mafis/239452 to your computer and use it in GitHub Desktop.
@import "../Extensions/CPViewController/CPViewController.j"
@import "../Extensions/CPActiveRecord/CPActiveRecord.j"
@implementation TableViewController : UIViewController
{
CPArray data;
CPActiveRecord record @accessors;
@outlet CPTableView tableView;
}
- (void)awakeFromCib
{
// CPLog("TableViewController");
[tableView setDataSource:data];
[tableView setTarget:self];
[tableView setDelegate:self];
[tableView setDoubleAction:@selector(doubleClick:)];
//CPLog(record);
if(record)
{
[[record class] addObserver:self selector:@selector(recordDidLoad:)];
}
}
-(void)setData:(CPArray)array
{
CPLog(array);
if (data != array)
{
data = array;
[tableView setDataSource:data];
[tableView reloadData];
}
}
- (void)recordDidLoad:(CPNotification)aNotification
{
//CPLog("Set Tableview data");
// CPLog("Record : " + record);
if([record isKindOfClass:CPActiveRecord])
{
// CPLog("Record is ActiveRecord Subclass");
[self setData:[[record class] all]];
}
}
- (void)doubleClick:(CPNotification)aNotification
{
CPLog(aNotification);
}
@end
@implementation CPArray (CPTableDataSource)
- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aTableColumn row:(int)rowIndex
{
// ([[self objectAtIndex:rowIndex] title]);
return [[self objectAtIndex:rowIndex] title];
}
- (int)numberOfRowsInTableView:(CPTableView)aTableView
{
return [self count];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment