Created
November 20, 2009 11:54
-
-
Save mafis/239452 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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